运行 一个 Node.js 环境中的多个 Parse 服务器实例
Running multiple Parse server instance in one Node.js environment
有没有办法在一个 Node.js(一台机器)环境中 运行 多个 Parse 服务器实例?如果是,配置是什么。
我特别针对 Jelastic,但我认为通用解决方案无论如何都适用。
您可以将 cluster module 用于同一服务器应用程序的 运行 多个实例。
请注意,Node.js 或您的程序中没有路由逻辑,工作人员之间也没有共享状态。因此,重要的是要设计您的程序,使其不会过度依赖内存中的数据对象来进行会话和登录等操作。
我正在使用这种方式并且效果很好
// First app instance here
var api1 = new ParseServer({
databaseURI: 'mongodb://localhost:27017/dev1',
cloud: '/home/myApp/cloud/main1.js',
appId: 'myAppId1',
masterKey: 'myMasterKey1',
fileKey: 'optionalFileKey1',
serverURL: 'http://localhost:1337/parse'
});
// Second app instance here
var api2 = new ParseServer({
databaseURI: 'mongodb://localhost:27017/dev2', // Connection string foryour MongoDB database
cloud: '/home/myApp/cloud/main2.js', // Absolute path to your Cloud Code
appId: 'myAppId2',
masterKey: 'myMasterKey2', // 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
var mountPath = process.env.PARSE_MOUNT || '/parse';
// Mount Apps here
app.use(mountPath, api1);
app.use(mountPath, api2);
希望对您有所帮助!!让我知道
有没有办法在一个 Node.js(一台机器)环境中 运行 多个 Parse 服务器实例?如果是,配置是什么。
我特别针对 Jelastic,但我认为通用解决方案无论如何都适用。
您可以将 cluster module 用于同一服务器应用程序的 运行 多个实例。 请注意,Node.js 或您的程序中没有路由逻辑,工作人员之间也没有共享状态。因此,重要的是要设计您的程序,使其不会过度依赖内存中的数据对象来进行会话和登录等操作。
我正在使用这种方式并且效果很好
// First app instance here
var api1 = new ParseServer({
databaseURI: 'mongodb://localhost:27017/dev1',
cloud: '/home/myApp/cloud/main1.js',
appId: 'myAppId1',
masterKey: 'myMasterKey1',
fileKey: 'optionalFileKey1',
serverURL: 'http://localhost:1337/parse'
});
// Second app instance here
var api2 = new ParseServer({
databaseURI: 'mongodb://localhost:27017/dev2', // Connection string foryour MongoDB database
cloud: '/home/myApp/cloud/main2.js', // Absolute path to your Cloud Code
appId: 'myAppId2',
masterKey: 'myMasterKey2', // 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
var mountPath = process.env.PARSE_MOUNT || '/parse';
// Mount Apps here
app.use(mountPath, api1);
app.use(mountPath, api2);
希望对您有所帮助!!让我知道