Files
kami-parse-server/src/cli/parse-server.js

80 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-02-24 08:50:04 -05:00
import path from 'path';
import express from 'express';
2016-02-24 14:20:24 -05:00
import { ParseServer } from '../index';
2016-02-24 08:50:04 -05:00
import definitions from './cli-definitions';
import program from './utils/commander';
import colors from 'colors';
2016-02-19 20:16:14 -05:00
program.loadDefinitions(definitions);
program
.usage('[options] <path/to/configuration.json>');
program.on('--help', function(){
console.log(' Get Started guide:');
console.log('');
console.log(' Please have a look at the get started guide!')
console.log(' https://github.com/ParsePlatform/parse-server/wiki/Parse-Server-Guide');
console.log('');
console.log('');
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');
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');
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('');
});
program.parse(process.argv, process.env);
2016-02-25 19:07:17 -05:00
let options = {};
2016-02-19 20:16:14 -05:00
if (program.args.length > 0 ) {
2016-02-24 08:50:04 -05:00
let jsonPath = program.args[0];
2016-02-19 20:16:14 -05:00
jsonPath = path.resolve(jsonPath);
options = require(jsonPath);
console.log(`Configuation loaded from ${jsonPath}`)
}
options = Object.keys(definitions).reduce(function (options, key) {
2016-02-19 20:16:14 -05:00
if (program[key]) {
options[key] = program[key];
}
return options;
}, options);
if (!options.serverURL) {
options.serverURL = `http://localhost:${options.port}${options.mountPath}`;
}
2016-02-19 20:16:14 -05:00
if (!options.appId || !options.masterKey || !options.serverURL) {
program.outputHelp();
console.error("");
console.error(colors.red("ERROR: appId, masterKey and serverURL are required"));
console.error("");
process.exit(1);
}
2016-02-24 08:50:04 -05:00
const app = express();
const api = new ParseServer(options);
2016-02-19 20:16:14 -05:00
app.use(options.mountPath, api);
2016-02-24 08:50:04 -05:00
app.listen(options.port, function() {
2016-02-19 20:16:14 -05:00
for (let key in options) {
2016-02-24 08:50:04 -05:00
let value = options[key];
2016-02-19 20:16:14 -05:00
if (key == "masterKey") {
value = "***REDACTED***";
}
console.log(`${key}: ${value}`);
}
console.log('');
console.log('parse-server running on '+options.serverURL);
2016-02-19 20:16:14 -05:00
});