简体   繁体   中英

Parse server mixed up the configuration

I am using several app's with same parse server hosted on my AWS EC2 server. And two apps mixed up. Let me explain with an example:

I have app1 with db1 mongodb, user1 mongodb user, master1 master key, and app1 appId. And I have app2 with db2 mongodb, user2 mongodb user, master2 master key, and app2 appId. Both have their own cloud code.

When I try to create an object from app2 with its cloud code and create an object, cloud code creates this object at app1's db1.

I tried to delete db2 and user2 and re-create them with new appId, new master key and password. But nothing is changed.

This is a part of server.js configuration:

var app = express();
var mountPath = '/parse';

var api1 = new ParseServer({
  databaseURI: 'mongodb://app1:pass1@localhost:27017/app1',
  appId      : 'appId1',
  masterKey  : 'master1',
  serverURL  : 'http://127.0.0.1:1337/parse',
  publicServerURL: 'https://my.company.com/parse',
  cloud: './cloud/app1/main.js',
  allowClientClassCreation: false,
});
app.use(mountPath, api1);

var api2 = new ParseServer({
  databaseURI: 'mongodb://app2:pass2@localhost:27017/app2',
  appId      : 'appId2',
  masterKey  : 'master2',
  serverURL  : 'http://127.0.0.1:1337/parse',
  publicServerURL: 'https://my.company.com/parse',
  cloud: './cloud/app2/main.js',
  allowClientClassCreation: false,
});
app.use(mountPath, api2);

What is wrong and how can I get rid of this problem? Thanks

I assume that in your cloud code you are using the Parse JS SDK to query the servers. The problem with the JS SDK is that it uses globals and a single Parse instance basically which you initialize somewhere with the application ID and server URL. Whenever you call Parse.initialize(...) with an application ID, the following queries will use that application ID in the requests. Maybe you could reinitialize before every query but that's probably not a good idea as it is error prone and timing might even break this n.netheless. Better to run the parse server instances in different processes as suggested in the comments.

See also this discussion about it: https://github.com/parse-community/Parse-SDK-JS/issues/203

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM