Skip to content

Question: Do I need one Instances for each App? #51

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

Closed
SaifAlDilaimi opened this issue Jan 29, 2016 · 11 comments
Closed

Question: Do I need one Instances for each App? #51

SaifAlDilaimi opened this issue Jan 29, 2016 · 11 comments

Comments

@SaifAlDilaimi
Copy link

Hello Parse-Team ;(

I was in technical mourning the whole day in my bed and since its 10pm here I thought I should stop wining. Thaanks first of that you guys decided to still support the open source stuff. Could have been worst...

Well to my question: Do I need for each app from now on a single parse-server instance? I have apps that depend on parse but have not that much of traction to get their own server. I'm I right that I need multple instances??

PS: Couldn't you post it on a monday? Mondays sucks anyway..

@francocorreasosa
Copy link

Yes but you can do it very easily.

Example:

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

var app = express();

// Specify the connection string for your mongodb database
// and the location to your Parse cloud code
var app1 = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/app1',
  cloud: '/home/parse/example/cloudcode/main.js', // Provide an absolute path
  appId: 'gXQvHLskP1ej38OQ7CjIqgbRs01ZCMznbcxSm1B',
  masterKey: 'W8VquvQsd8ejded8jD1CKmKs1OqQINEgRa7NXDCYF'
});

var app2 = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/app2',
  cloud: '/home/parse/example2/cloudcode/main.js', // Provide an absolute path
  appId: 'fndfHLskP1ef38OQdCjIqgbRs01ZCMznbcxde8',
  masterKey: 'mdfmQsd8djaed8jD1CKmKs1OqQINEgRa7NXFJDdf'
});


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

// Hello world
app.get('/app1', function(req, res) {
  res.status(200).send('Express is running here for app1.');
});

app.get('/app2', function(req, res) {
  res.status(200).send('Express is running here for app2.');
});

var port = process.env.PORT || 5000;
app.listen(port, function() {
  console.log('parse-server-example running on port ' + port + '.');
});

@francocorreasosa
Copy link

Or having different files and manage them with pm2 as I do

┌───────────────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name          │ id │ mode │ pid  │ status │ restart │ uptime │ memory      │ watching │
├───────────────────┼────┼──────┼──────┼────────┼─────────┼────────┼─────────────┼──────────┤
│ mongod            │ 2  │ fork │ 5503 │ online │ 14      │ 57m    │ 31.230 MB   │ disabled │
│ app1-server       │ 3  │ fork │ 6286 │ online │ 1       │ 39m    │ 13.750 MB   │ disabled │
│ app2-server       │ 4  │ fork │ 6232 │ online │ 1       │ 38m    │ 11.359 MB   │ disabled │
└───────────────────┴────┴──────┴──────┴────────┴─────────┴────────┴─────────────┴──────────┘

@kingmatusevich
Copy link

Or run multiple docker containers in the same server host, and mapping the parse-server port to a different port per app, You've got plenty of ports to spare and it would be very safe, independent and scalable.

@gfosco
Copy link
Contributor

gfosco commented Jan 29, 2016

Just to note that if they are in the same scope, what is not modularized is cloud code and Parse.initialize. If you're running multiple ParseServer instances, they will be writing over each others cloud code and appId/masterkey for client functions.

@SaifAlDilaimi
Copy link
Author

mhh.. so this wasn't a criterium for parse-server.. It just would make sense for a server to support multiple apps.

@gfosco does it override also the keys and cloud code on the example of @francocorreasosa ?

@francocorreasosa
Copy link

What about this?

var express = require('express');
var ParseServerApp1, ParseServerApp2 = require('parse-server').ParseServer;


var app = express();

// Specify the connection string for your mongodb database
// and the location to your Parse cloud code
var app1 = new ParseServerApp1({
  databaseURI: 'mongodb://localhost:27017/app1',
  cloud: '/home/parse/example/cloudcode/main.js', // Provide an absolute path
  appId: 'gXQvHLskP1ej38OQ7CjIqgbRs01ZCMznbcxSm1B',
  masterKey: 'W8VquvQsd8ejded8jD1CKmKs1OqQINEgRa7NXDCYF'
});

var app2 = new ParseServerApp2({
  databaseURI: 'mongodb://localhost:27017/app2',
  cloud: '/home/parse/example2/cloudcode/main.js', // Provide an absolute path
  appId: 'fndfHLskP1ef38OQdCjIqgbRs01ZCMznbcxde8',
  masterKey: 'mdfmQsd8djaed8jD1CKmKs1OqQINEgRa7NXFJDdf'
});


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

// Hello world
app.get('/app1', function(req, res) {
  res.status(200).send('Express is running here for app1.');
});

app.get('/app2', function(req, res) {
  res.status(200).send('Express is running here for app2.');
});

var port = process.env.PORT || 5000;
app.listen(port, function() {
  console.log('parse-server-example running on port ' + port + '.');
});

The ParseServer "class" it's wrong implemented anyway. It should have a scope for each instance. Maybe fixing the class implementation helps.

@gfosco
Copy link
Contributor

gfosco commented Jan 29, 2016

That wouldn't fix it because globals.Parse is mutated.

@SaifAlDilaimi
Copy link
Author

So as far as I understood even the workaround of @francocorreasosa doesnt solve the problem?

@francocorreasosa
Copy link

Exactly. You have to run it on different processes and different internal ports. You can merge the ports into subdomains with a reverse proxy (nginx)

@asoyfer
Copy link

asoyfer commented Jan 30, 2016

Running multiple docker containers as @kingmatusevich mentioned would also work but that assumes you want to learn all about that lol

Running multiple Parse-Server apps in one instance of express via vhost would obv be the best for small apps. @gfosco any chance, you guys would have the time to build that in or is it less than trivial?

Thanks

@misaghDroid
Copy link

Yes but you can do it very easily.

Example:

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

var app = express();

// Specify the connection string for your mongodb database
// and the location to your Parse cloud code
var app1 = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/app1',
  cloud: '/home/parse/example/cloudcode/main.js', // Provide an absolute path
  appId: 'gXQvHLskP1ej38OQ7CjIqgbRs01ZCMznbcxSm1B',
  masterKey: 'W8VquvQsd8ejded8jD1CKmKs1OqQINEgRa7NXDCYF'
});

var app2 = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/app2',
  cloud: '/home/parse/example2/cloudcode/main.js', // Provide an absolute path
  appId: 'fndfHLskP1ef38OQdCjIqgbRs01ZCMznbcxde8',
  masterKey: 'mdfmQsd8djaed8jD1CKmKs1OqQINEgRa7NXFJDdf'
});


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

// Hello world
app.get('/app1', function(req, res) {
  res.status(200).send('Express is running here for app1.');
});

app.get('/app2', function(req, res) {
  res.status(200).send('Express is running here for app2.');
});

var port = process.env.PORT || 5000;
app.listen(port, function() {
  console.log('parse-server-example running on port ' + port + '.');
});

I have problem and the last db overwrite for all app? Do you have any idea about that?

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

8 participants