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

Got multiple apps working on one server successfully, why no official support? #1979

Closed
ahmadhashemi opened this issue Jun 2, 2016 · 8 comments

Comments

@ahmadhashemi
Copy link

Like most of Parse.com users, I've got multiple applications running in my Parse account. So I was curious to know if there is any way to do this on a self-hosted parse server or not. After trying different approaches (even running independent server per application, which is a crazy idea!) this is my final configuration which make me able to run multiple applications on one parse server:

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

var first = new ParseServer({
  databaseURI: ' ,.',
  appId: ' ,.',
  masterKey: ' ,.',
  serverURL: 'http://localhost:1400/parse',
  cloud:  'cloud/first.js'
});

var second = new ParseServer({
  databaseURI: ' ,.',
  appId: ' ,.',
  masterKey: ' ,.',
  serverURL: 'http://localhost:1400/parse',
  cloud:  'cloud/second.js'
});

var app = express();

app.use('/parse', first);
app.use('/parse', second);

var port = 1400;
var httpServer = require('http').createServer(app);

httpServer.listen(port, 'localhost');

With this configuration inside index.js file, I was able to make both application running on https://mydomain.com/parse and each could be authorized using their own appId and masterKey. Even Cloud Code for each application is working without any problem.

The point is that, why this ability isn't officially documented? Parse developers are saying that running multiple applications on same server isn't supported (Even when I want to run parse-server with terminal command and a configuration for multiple applications, I get an error saying running multiple applications isn't supported). But as I said, I was able to this by editing index.js file in source code like above.

All of these things make me think that I'm missing something. Am I?!

@flovilmart
Copy link
Contributor

Concurrent cloud code requests will affect the Parse js SDK and the applicationId won't match.

There is a big chance that all cloud code requests for your first app will end up affecting your second. So yes, that works only if you don't use cloud code

@drew-gross
Copy link
Contributor

This issue is asynchronous Cloud Code. The issues will only show up when a) both apps are receiving requests at the same time, and b) your Cloud Code does asynchronous stuff like making queries or writes.

@ahmadhashemi
Copy link
Author

ahmadhashemi commented Jun 2, 2016

Oh, now I see. I'd experienced an interesting issue while configuring parse server in my way. Whenever I didn't set serverURL for one of applications, other applications couldn't send requests to their own databases either! (which logically is odd. because one application may use Cloud Code and other may not). So Cloud Code gets broken is some way with this configuration.

Thank you @flovilmart and @drew-gross for pointing this out. Since hosting multiple applications is more important than using Cloud Code for me, I will abandon Cloud Code for now, and use PHP requests to simulate Cloud Code functionality in my applications.

@drew-gross
Copy link
Contributor

You could also run multiple parse servers in multiple processes, on different subdomains or ports.

@ahmadhashemi
Copy link
Author

I missed a little thing. The problem you said about Cloud Code, is it because of using one server for all applications, or sharing /parse as mount path? I mean, can this problem be solved by using exclusive mount path for each application?
As @flovilmart said, problem is inside Parse JS SDK and I think it has nothing to do with mount path. But I want to make sure.

@flovilmart
Copy link
Contributor

The JSSDK is a global object, you will encounter problems with your cloud code as soon as you have concurrent calls on your apps.

@jkassis
Copy link

jkassis commented Feb 12, 2017

@flovilmart @drew-gross My cloud code is running. The only problem seems to be that the internal serverURL is shared so that requests to the cloud API go to the same URL. Can you point me to the singleton object. I'd like to attempt to fix this.

@flovilmart
Copy link
Contributor

the whole JS SDK is a singleton, probably other parts of parse-server don't play well with multiple apps.

The only problem seems to be

That's not the only problem, also your appId, jsKey, context, variables. if another request comes in when processing the previous one from another app, your whole context would get f...d up.

If you're unsure, please read: #263

and particularly: #263 (comment)

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

4 participants