2016-11-24 15:47:41 -05:00
|
|
|
/* eslint-disable no-console */
|
2017-05-08 13:06:01 -04:00
|
|
|
import ParseServer from '../index';
|
2016-09-24 13:34:05 -04:00
|
|
|
import definitions from './definitions/parse-server';
|
2016-08-29 21:43:35 -04:00
|
|
|
import cluster from 'cluster';
|
|
|
|
|
import os from 'os';
|
2016-09-24 13:34:05 -04:00
|
|
|
import runner from './utils/runner';
|
2016-02-19 20:16:14 -05:00
|
|
|
|
2020-07-13 13:06:52 -05:00
|
|
|
const help = function () {
|
2016-02-19 20:16:14 -05:00
|
|
|
console.log(' Get Started guide:');
|
|
|
|
|
console.log('');
|
2016-11-30 13:48:49 +00:00
|
|
|
console.log(' Please have a look at the get started guide!');
|
2017-10-12 19:40:47 -07:00
|
|
|
console.log(' http://docs.parseplatform.org/parse-server/guide/');
|
2016-02-19 20:16:14 -05:00
|
|
|
console.log('');
|
|
|
|
|
console.log('');
|
|
|
|
|
console.log(' Usage with npm start');
|
|
|
|
|
console.log('');
|
|
|
|
|
console.log(' $ npm start -- path/to/config.json');
|
2020-10-25 15:06:58 -05:00
|
|
|
console.log(' $ npm start -- --appId APP_ID --masterKey MASTER_KEY --serverURL serverURL');
|
|
|
|
|
console.log(' $ npm start -- --appId APP_ID --masterKey MASTER_KEY --serverURL serverURL');
|
2016-02-19 20:16:14 -05:00
|
|
|
console.log('');
|
|
|
|
|
console.log('');
|
|
|
|
|
console.log(' Usage:');
|
|
|
|
|
console.log('');
|
|
|
|
|
console.log(' $ parse-server path/to/config.json');
|
2020-10-25 15:06:58 -05:00
|
|
|
console.log(' $ parse-server -- --appId APP_ID --masterKey MASTER_KEY --serverURL serverURL');
|
|
|
|
|
console.log(' $ parse-server -- --appId APP_ID --masterKey MASTER_KEY --serverURL serverURL');
|
2016-02-19 20:16:14 -05:00
|
|
|
console.log('');
|
2016-09-24 13:34:05 -04:00
|
|
|
};
|
2016-08-29 21:43:35 -04:00
|
|
|
|
2016-09-24 13:34:05 -04:00
|
|
|
runner({
|
|
|
|
|
definitions,
|
|
|
|
|
help,
|
|
|
|
|
usage: '[options] <path/to/configuration.json>',
|
2020-07-13 13:06:52 -05:00
|
|
|
start: function (program, options, logOptions) {
|
2017-10-23 08:43:05 -04:00
|
|
|
if (!options.appId || !options.masterKey) {
|
2016-09-24 13:34:05 -04:00
|
|
|
program.outputHelp();
|
2018-09-01 13:58:06 -04:00
|
|
|
console.error('');
|
2020-10-25 15:06:58 -05:00
|
|
|
console.error('\u001b[31mERROR: appId and masterKey are required\u001b[0m');
|
2018-09-01 13:58:06 -04:00
|
|
|
console.error('');
|
2016-09-24 13:34:05 -04:00
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-01 13:58:06 -04:00
|
|
|
if (options['liveQuery.classNames']) {
|
2016-09-24 13:34:05 -04:00
|
|
|
options.liveQuery = options.liveQuery || {};
|
2018-09-01 13:58:06 -04:00
|
|
|
options.liveQuery.classNames = options['liveQuery.classNames'];
|
|
|
|
|
delete options['liveQuery.classNames'];
|
2016-09-24 13:34:05 -04:00
|
|
|
}
|
2018-09-01 13:58:06 -04:00
|
|
|
if (options['liveQuery.redisURL']) {
|
2016-09-24 13:34:05 -04:00
|
|
|
options.liveQuery = options.liveQuery || {};
|
2018-09-01 13:58:06 -04:00
|
|
|
options.liveQuery.redisURL = options['liveQuery.redisURL'];
|
|
|
|
|
delete options['liveQuery.redisURL'];
|
2016-09-24 13:34:05 -04:00
|
|
|
}
|
2019-05-11 19:13:41 -05:00
|
|
|
if (options['liveQuery.redisOptions']) {
|
|
|
|
|
options.liveQuery = options.liveQuery || {};
|
|
|
|
|
options.liveQuery.redisOptions = options['liveQuery.redisOptions'];
|
|
|
|
|
delete options['liveQuery.redisOptions'];
|
|
|
|
|
}
|
2016-09-24 13:34:05 -04:00
|
|
|
|
|
|
|
|
if (options.cluster) {
|
2020-10-25 15:06:58 -05:00
|
|
|
const numCPUs = typeof options.cluster === 'number' ? options.cluster : os.cpus().length;
|
2016-09-24 13:34:05 -04:00
|
|
|
if (cluster.isMaster) {
|
2016-11-30 13:48:49 +00:00
|
|
|
logOptions();
|
2018-09-01 13:58:06 -04:00
|
|
|
for (let i = 0; i < numCPUs; i++) {
|
2016-09-24 13:34:05 -04:00
|
|
|
cluster.fork();
|
|
|
|
|
}
|
2016-11-24 15:47:41 -05:00
|
|
|
cluster.on('exit', (worker, code) => {
|
2020-10-25 15:06:58 -05:00
|
|
|
console.log(`worker ${worker.process.pid} died (${code})... Restarting`);
|
2016-09-24 13:34:05 -04:00
|
|
|
cluster.fork();
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2022-12-22 01:30:13 +11:00
|
|
|
ParseServer.startApp(options)
|
|
|
|
|
.then(() => {
|
|
|
|
|
printSuccessMessage();
|
|
|
|
|
})
|
|
|
|
|
.catch(e => {
|
|
|
|
|
console.error(e);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|
2016-09-24 13:34:05 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2022-12-22 01:30:13 +11:00
|
|
|
ParseServer.startApp(options)
|
|
|
|
|
.then(() => {
|
|
|
|
|
logOptions();
|
|
|
|
|
console.log('');
|
|
|
|
|
printSuccessMessage();
|
|
|
|
|
})
|
|
|
|
|
.catch(e => {
|
|
|
|
|
console.error(e);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|
2019-06-25 14:44:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function printSuccessMessage() {
|
2020-10-25 15:06:58 -05:00
|
|
|
console.log('[' + process.pid + '] parse-server running on ' + options.serverURL);
|
2019-06-25 14:44:23 -07:00
|
|
|
if (options.mountGraphQL) {
|
2018-09-01 13:58:06 -04:00
|
|
|
console.log(
|
2019-06-25 14:44:23 -07:00
|
|
|
'[' +
|
|
|
|
|
process.pid +
|
|
|
|
|
'] GraphQL running on http://localhost:' +
|
|
|
|
|
options.port +
|
|
|
|
|
options.graphQLPath
|
2018-09-01 13:58:06 -04:00
|
|
|
);
|
2019-06-25 14:44:23 -07:00
|
|
|
}
|
|
|
|
|
if (options.mountPlayground) {
|
|
|
|
|
console.log(
|
|
|
|
|
'[' +
|
|
|
|
|
process.pid +
|
|
|
|
|
'] Playground running on http://localhost:' +
|
|
|
|
|
options.port +
|
|
|
|
|
options.playgroundPath
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-08-29 21:43:35 -04:00
|
|
|
}
|
2018-09-01 13:58:06 -04:00
|
|
|
},
|
2016-11-30 13:48:49 +00:00
|
|
|
});
|
2016-09-24 13:34:05 -04:00
|
|
|
|
2016-11-24 15:47:41 -05:00
|
|
|
/* eslint-enable no-console */
|