@@ -1,2 +1,3 @@
|
||||
const LiveQueryServerOptions = require('../../Options/Definitions').LiveQueryServerOptions;
|
||||
const LiveQueryServerOptions = require('../../Options/Definitions')
|
||||
.LiveQueryServerOptions;
|
||||
export default LiveQueryServerOptions;
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
const ParseServerDefinitions = require('../../Options/Definitions').ParseServerOptions;
|
||||
const ParseServerDefinitions = require('../../Options/Definitions')
|
||||
.ParseServerOptions;
|
||||
export default ParseServerDefinitions;
|
||||
|
||||
@@ -7,5 +7,5 @@ runner({
|
||||
start: function(program, options, logOptions) {
|
||||
logOptions();
|
||||
ParseServer.createLiveQueryServer(undefined, options);
|
||||
}
|
||||
})
|
||||
},
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import cluster from 'cluster';
|
||||
import os from 'os';
|
||||
import runner from './utils/runner';
|
||||
|
||||
const help = function(){
|
||||
const help = function() {
|
||||
console.log(' Get Started guide:');
|
||||
console.log('');
|
||||
console.log(' Please have a look at the get started guide!');
|
||||
@@ -15,15 +15,23 @@ const help = function(){
|
||||
console.log(' Usage with npm start');
|
||||
console.log('');
|
||||
console.log(' $ npm start -- path/to/config.json');
|
||||
console.log(' $ npm start -- --appId APP_ID --masterKey MASTER_KEY --serverURL serverURL');
|
||||
console.log(' $ npm start -- --appId APP_ID --masterKey MASTER_KEY --serverURL serverURL');
|
||||
console.log(
|
||||
' $ npm start -- --appId APP_ID --masterKey MASTER_KEY --serverURL serverURL'
|
||||
);
|
||||
console.log(
|
||||
' $ npm start -- --appId APP_ID --masterKey MASTER_KEY --serverURL serverURL'
|
||||
);
|
||||
console.log('');
|
||||
console.log('');
|
||||
console.log(' Usage:');
|
||||
console.log('');
|
||||
console.log(' $ parse-server path/to/config.json');
|
||||
console.log(' $ parse-server -- --appId APP_ID --masterKey MASTER_KEY --serverURL serverURL');
|
||||
console.log(' $ parse-server -- --appId APP_ID --masterKey MASTER_KEY --serverURL serverURL');
|
||||
console.log(
|
||||
' $ parse-server -- --appId APP_ID --masterKey MASTER_KEY --serverURL serverURL'
|
||||
);
|
||||
console.log(
|
||||
' $ parse-server -- --appId APP_ID --masterKey MASTER_KEY --serverURL serverURL'
|
||||
);
|
||||
console.log('');
|
||||
};
|
||||
|
||||
@@ -34,47 +42,58 @@ runner({
|
||||
start: function(program, options, logOptions) {
|
||||
if (!options.appId || !options.masterKey) {
|
||||
program.outputHelp();
|
||||
console.error("");
|
||||
console.error('\u001b[31mERROR: appId and masterKey are required\u001b[0m');
|
||||
console.error("");
|
||||
console.error('');
|
||||
console.error(
|
||||
'\u001b[31mERROR: appId and masterKey are required\u001b[0m'
|
||||
);
|
||||
console.error('');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (options["liveQuery.classNames"]) {
|
||||
if (options['liveQuery.classNames']) {
|
||||
options.liveQuery = options.liveQuery || {};
|
||||
options.liveQuery.classNames = options["liveQuery.classNames"];
|
||||
delete options["liveQuery.classNames"];
|
||||
options.liveQuery.classNames = options['liveQuery.classNames'];
|
||||
delete options['liveQuery.classNames'];
|
||||
}
|
||||
if (options["liveQuery.redisURL"]) {
|
||||
if (options['liveQuery.redisURL']) {
|
||||
options.liveQuery = options.liveQuery || {};
|
||||
options.liveQuery.redisURL = options["liveQuery.redisURL"];
|
||||
delete options["liveQuery.redisURL"];
|
||||
options.liveQuery.redisURL = options['liveQuery.redisURL'];
|
||||
delete options['liveQuery.redisURL'];
|
||||
}
|
||||
|
||||
if (options.cluster) {
|
||||
const numCPUs = typeof options.cluster === 'number' ? options.cluster : os.cpus().length;
|
||||
const numCPUs =
|
||||
typeof options.cluster === 'number'
|
||||
? options.cluster
|
||||
: os.cpus().length;
|
||||
if (cluster.isMaster) {
|
||||
logOptions();
|
||||
for(let i = 0; i < numCPUs; i++) {
|
||||
for (let i = 0; i < numCPUs; i++) {
|
||||
cluster.fork();
|
||||
}
|
||||
cluster.on('exit', (worker, code) => {
|
||||
console.log(`worker ${worker.process.pid} died (${code})... Restarting`);
|
||||
console.log(
|
||||
`worker ${worker.process.pid} died (${code})... Restarting`
|
||||
);
|
||||
cluster.fork();
|
||||
});
|
||||
} else {
|
||||
ParseServer.start(options, () => {
|
||||
console.log('[' + process.pid + '] parse-server running on ' + options.serverURL);
|
||||
console.log(
|
||||
'[' + process.pid + '] parse-server running on ' + options.serverURL
|
||||
);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
ParseServer.start(options, () => {
|
||||
logOptions();
|
||||
console.log('');
|
||||
console.log('[' + process.pid + '] parse-server running on ' + options.serverURL);
|
||||
console.log(
|
||||
'[' + process.pid + '] parse-server running on ' + options.serverURL
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/* eslint-enable no-console */
|
||||
|
||||
@@ -9,12 +9,20 @@ Command.prototype.loadDefinitions = function(definitions) {
|
||||
_definitions = definitions;
|
||||
|
||||
Object.keys(definitions).reduce((program, opt) => {
|
||||
if (typeof definitions[opt] == "object") {
|
||||
if (typeof definitions[opt] == 'object') {
|
||||
const additionalOptions = definitions[opt];
|
||||
if (additionalOptions.required === true) {
|
||||
return program.option(`--${opt} <${opt}>`, additionalOptions.help, additionalOptions.action);
|
||||
return program.option(
|
||||
`--${opt} <${opt}>`,
|
||||
additionalOptions.help,
|
||||
additionalOptions.action
|
||||
);
|
||||
} else {
|
||||
return program.option(`--${opt} [${opt}]`, additionalOptions.help, additionalOptions.action);
|
||||
return program.option(
|
||||
`--${opt} [${opt}]`,
|
||||
additionalOptions.help,
|
||||
additionalOptions.action
|
||||
);
|
||||
}
|
||||
}
|
||||
return program.option(`--${opt} [${opt}]`);
|
||||
@@ -22,7 +30,7 @@ Command.prototype.loadDefinitions = function(definitions) {
|
||||
|
||||
_reverseDefinitions = Object.keys(definitions).reduce((object, key) => {
|
||||
let value = definitions[key];
|
||||
if (typeof value == "object") {
|
||||
if (typeof value == 'object') {
|
||||
value = value.env;
|
||||
}
|
||||
if (value) {
|
||||
@@ -32,17 +40,17 @@ Command.prototype.loadDefinitions = function(definitions) {
|
||||
}, {});
|
||||
|
||||
_defaults = Object.keys(definitions).reduce((defs, opt) => {
|
||||
if(_definitions[opt].default) {
|
||||
if (_definitions[opt].default) {
|
||||
defs[opt] = _definitions[opt].default;
|
||||
}
|
||||
return defs;
|
||||
}, {});
|
||||
|
||||
/* istanbul ignore next */
|
||||
this.on('--help', function(){
|
||||
this.on('--help', function() {
|
||||
console.log(' Configure From Environment:');
|
||||
console.log('');
|
||||
Object.keys(_reverseDefinitions).forEach((key) => {
|
||||
Object.keys(_reverseDefinitions).forEach(key => {
|
||||
console.log(` $ ${key}='${_reverseDefinitions[key]}'`);
|
||||
});
|
||||
console.log('');
|
||||
@@ -53,8 +61,8 @@ function parseEnvironment(env = {}) {
|
||||
return Object.keys(_reverseDefinitions).reduce((options, key) => {
|
||||
if (env[key]) {
|
||||
const originalKey = _reverseDefinitions[key];
|
||||
let action = (option) => (option);
|
||||
if (typeof _definitions[originalKey] === "object") {
|
||||
let action = option => option;
|
||||
if (typeof _definitions[originalKey] === 'object') {
|
||||
action = _definitions[originalKey].action || action;
|
||||
}
|
||||
options[_reverseDefinitions[key]] = action(env[key]);
|
||||
@@ -77,7 +85,7 @@ function parseConfigFile(program) {
|
||||
} else {
|
||||
options = jsonConfig;
|
||||
}
|
||||
Object.keys(options).forEach((key) => {
|
||||
Object.keys(options).forEach(key => {
|
||||
const value = options[key];
|
||||
if (!_definitions[key]) {
|
||||
throw `error: unknown option ${key}`;
|
||||
@@ -87,13 +95,13 @@ function parseConfigFile(program) {
|
||||
options[key] = action(value);
|
||||
}
|
||||
});
|
||||
console.log(`Configuration loaded from ${jsonPath}`)
|
||||
console.log(`Configuration loaded from ${jsonPath}`);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
Command.prototype.setValuesIfNeeded = function(options) {
|
||||
Object.keys(options).forEach((key) => {
|
||||
Object.keys(options).forEach(key => {
|
||||
if (!this.hasOwnProperty(key)) {
|
||||
this[key] = options[key];
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
|
||||
import program from './commander';
|
||||
|
||||
function logStartupOptions(options) {
|
||||
for (const key in options) {
|
||||
let value = options[key];
|
||||
if (key == "masterKey") {
|
||||
value = "***REDACTED***";
|
||||
if (key == 'masterKey') {
|
||||
value = '***REDACTED***';
|
||||
}
|
||||
if (typeof value === 'object') {
|
||||
try {
|
||||
value = JSON.stringify(value)
|
||||
} catch(e) {
|
||||
value = JSON.stringify(value);
|
||||
} catch (e) {
|
||||
if (value && value.constructor && value.constructor.name) {
|
||||
value = value.constructor.name;
|
||||
}
|
||||
@@ -22,12 +21,7 @@ function logStartupOptions(options) {
|
||||
}
|
||||
}
|
||||
|
||||
export default function({
|
||||
definitions,
|
||||
help,
|
||||
usage,
|
||||
start
|
||||
}) {
|
||||
export default function({ definitions, help, usage, start }) {
|
||||
program.loadDefinitions(definitions);
|
||||
if (usage) {
|
||||
program.usage(usage);
|
||||
|
||||
Reference in New Issue
Block a user