Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple apps on one server #116

Closed
samarthagarwal opened this issue Feb 1, 2016 · 30 comments
Closed

Multiple apps on one server #116

samarthagarwal opened this issue Feb 1, 2016 · 30 comments

Comments

@samarthagarwal
Copy link

Hi. I am trying to have multiple apps on one single parse-server deployment. How is it possible?
Since each app will have different app ids, Is it still possible for apps to coincide?

@samarthagarwal
Copy link
Author

Is connecting each app to a separate mongodb database, a good way to go?

@christianmarth
Copy link

I'm looking at doing the same thing, thinking will need to create a new database and instance of ParseServer for each app and map this to a different path, maybe something like this

var app1 = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/app1',
  cloud: '/home/app1/cloud/main.js', // Provide an absolute path
  appId: 'myAppId',
  masterKey: 'mySecretMasterKey',
  fileKey: 'optionalFileKey'
});

// Serve the Parse API on the /parse URL prefix
app.use('/app1', app1);

var app2 = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/app2',
  cloud: '/home/app2/cloud/main.js', // Provide an absolute path
  appId: 'myAppId',
  masterKey: 'mySecretMasterKey',
  fileKey: 'optionalFileKey'
});

// Serve the Parse API on the /parse URL prefix
app.use('/app2', app2);

@samarthagarwal
Copy link
Author

So if the client SDK connects to the url /parse, which parse-server instance will actually work? I don't think we should mount both to the same endpoint.

@christianmarth
Copy link

Sorry, i meant also change the url so you have /app1 /app2

@samarthagarwal
Copy link
Author

Do we have any open source dashboard like project that when used with parse-server can give us a Parse like dashboard? Is someone developing it? I am willing to write one myself.

@christianmarth
Copy link

Have a look at #3

I'm interested in contributing to a dashboard as well, for most of my apps, I've just written a custom CRUD dashboard in Javascript

@gfosco
Copy link
Contributor

gfosco commented Feb 2, 2016

Right now the main hurdle for multi-app support will be cloud code. The middleware which creates Parse.Cloud.define/etc will need to be updated similarly to #139 to somehow support separate cloud code initialization. Right now it's easy enough to run multiple from the database side... I'm going to close this for now but hope to see the server hosting multiple apps and cloud code in the not-too-distant future.

@gfosco gfosco closed this as completed Feb 2, 2016
@jamiechapman
Copy link

@gfosco funnily enough I was playing around with the middleware which deals with the Cloud Code functions yesterday (fairly similar to #139).

I managed to get the functions loaded up for different apps— but the brick wall in the end was the handleCloudFunction method inside functions.js. It's providing difficult to get the current appId at this stage of the request; for some reason req.body at that stage appears to be empty (even though I don't think it should be as bodyParser should have parsed it as JSON like it would in classes.js) — thus exposing _ApplicationId and allowing me to select the right Parse.Cloud function.

The other issue is the Parse library itself appears to be a global variable, so Parse.applicationId only returns the last defined application — and I guess this probably has a knock-on effect within the Cloud Code itself (e.g. when issuing queries and such?). So I guess that potentially would need some significant refactoring too?

@baluragala
Copy link

Does anyone has a workaround for multiple apps with different cloud codes? I have been trying to figure out a way to implement. any quick thoughts please?

@christianmarth
Copy link

Best solution currently is to just create two instances of parse server for now...

@kilabyte
Copy link

You can run the multi instance all in one index and use nodemon to manage the service when for when you makes changes or add another instance.

@lowgator
Copy link

Oddly, I have 100+ apps in my parse.com account. Does this mean these are all separate instances of Parse running?

@drew-gross
Copy link
Contributor

No, parse.com was massively multi-tenant. And as a result, massively complicated. You'll still be able to run your 100 apps on one MongoDB, but you will need separate instances of Parse Server.

@lowgator
Copy link

If a separate instance, that means I need to mount each parse instance on its own unique port right? Does Parse offer any consulting services ? I've been struggling all week to get a second app created on my hosted parse server.

@drew-gross
Copy link
Contributor

Yep, running each in it's own process and own it's own port should work. We don't have any consulting available, no.

@BrandenSandahl
Copy link

@drew-gross
If I am running a parse app by defining a custom index.js style file with my settings and then npm forever-ing it to keep it going, could I potentially just define a whole bunch of different custom index files and run them all, or would there be a better way to do this?

Hope that makes sense,
Thanks.

@grosscorporation
Copy link

@BrandenSandahl I'm gonna try that, makes sense.

@n00r
Copy link

n00r commented Jul 28, 2016

i will dynamically create parse server instance like back4app

@sowmiyas
Copy link

We are planning to have a single mongo db for all our apps by using the collectionPrefix field in parse server. How will this work once we export all data from parse to our own mongo? I am assuming that the export will create separate database for each app and collections will not have a prefix.

@georgesjamous
Copy link
Contributor

hello,
Can someone please clarify this for me. I am new to node and i am a bit lost.
Regarding running multiple apps...

I have on my ubuntu system. Parse-server installed in this directory /the directory/myserver/
The directory looks like this.

/the directory/myserver/node_modules
/the directory/myserver/package.json
/the directory/myserver/application0.js
/the directory/myserver/application1.js
/the directory/myserver/application2.js

and each application0.js, application1.js, application2.js
is on different port. 1337, 1338, 1339

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var app = express();

var api = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/dev', // Connection string for your MongoDB database
  cloud: '/home/myApp/cloud/main.js', // Absolute path to your Cloud Code
  appId: 'myAppId',
  masterKey: 'myMasterKey', // Keep this key secret!
  fileKey: 'optionalFileKey',
  serverURL: 'http://localhost:1337/parse' // Don't forget to change to https if needed
});

// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);

app.listen(1337, function() {
  console.log('parse-server-example running on port 1337.');
});

now if i run it this way, could this way be used
to run multiple apps with cloud code ?

node application0.js
node application1.js
node application2.js

The only way (for now) to run true multiple apps without affecting cloud code and global variables
is to run them like i did using different processes ?

@flovilmart
Copy link
Contributor

That seeems correct!

@natario1
Copy link

natario1 commented Jun 8, 2017

Regarding last comments, has anyone managed to do this in a GAE environment?

I can run the second app in its own process and port (e.g. 8081), allow the port in app.yaml and in firewall rules, but I see no way to specify the port when requesting myapp.appspot.com. You end up at their load balancer, and it directs to instance:8080 by default. At least, that's what I think is happening 😠

@richjing
Copy link

richjing commented Oct 2, 2017

take a look on this repo

  • run and manage multiple parse apps (instances) in a server and using a single port.

  • one code, one database, create a parse app in one second.

  • parse dashboard integrated, each app's manager can log into parse dashboard to manage their app.

  • one admin account in parse dashboard to manage all apps

@kerbymart
Copy link

Hello, @flovilmart so it seems with @georgesjam solution it is possible to run multiple parse on one server?

@flovilmart
Copy link
Contributor

Never said it was impossible, as long as you have each app isolated in it’s own process and a proxy to route to the right local port based on the application ID header.

I see pm2 has been used to spawn/manage each server process, which is actually a good way of doing so. You could also use pure nginx reverse proxy, docker containers, swarm, containers etc...

We won’t add multi app tenancy here as it doesn’t make sense, because of the plethora of options for doing so.

Multi app tenancy could be added by isolating the cloud code process out of parses-server but the performance implications are too high to make it practicle.

@kerbymart
Copy link

@flovilmart anyway the lib/index.js (from https://github.com/parse-community/parse-server) looks totally different from the parse-server-example

@flovilmart
Copy link
Contributor

What do you mean different? Parse-server-example is just an example usage of parse-server that I don’t recommend to use/fork. I personally use the CLI more and we should deprecate it in favor of the CLI.

@brianyyz
Copy link

@flovilmart can you give a couple of points on why you don't recommend using parse-server-example? I think many people use it as a springboard to get going with Parse and then never leave it.

@flovilmart
Copy link
Contributor

yeah that's the main reason actually, it's kinda a mess and doesn't encourage a proper way of managing your code either.

The CLI is powerful enough to accomplish a standalone parse-server. I'm not sure what's the best way to manage it. We're investigating yeoman generators and there's also the bootstrap.sh script that literally sets up a parse server in less than 30 seconds.

The CLI has the code to start the HTTP server, etc.. it may not fit every single use case, but it's easier to manage than the parse-server-example.

@rameshkec85
Copy link

take a look on this repo

  • run and manage multiple parse apps (instances) in a server and using a single port.
  • one code, one database, create a parse app in one second.
  • parse dashboard integrated, each app's manager can log into parse dashboard to manage their app.
  • one admin account in parse dashboard to manage all apps

Cloud functions are not working in this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests