From f16f3afd541a7c69cfc5ea686856716425af74c5 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Sat, 5 Mar 2016 09:37:38 -0500 Subject: [PATCH] Adds commander CLI - Adds support for --config, --port --allowInsecureHTTP - Adds support for PARSE_DASHBOARD_ALLOW_INSECURE_HTTP - Adds npm start script for easy deployments --- Parse-Dashboard/index.js | 22 +++++++++++++++++++--- README.md | 25 +++++++++++++++++++++++++ package.json | 5 ++++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/Parse-Dashboard/index.js b/Parse-Dashboard/index.js index a4dcef682b..d383f0ceab 100644 --- a/Parse-Dashboard/index.js +++ b/Parse-Dashboard/index.js @@ -5,6 +5,22 @@ * This source code is licensed under the license found in the LICENSE file in * the root directory of this source tree. */ +// Command line tool for npm start + +var DEFAULT_DASHBOARD_CONFIG = __dirname + '/parse-dashboard-config.json'; + +var program = require("commander"); +program.option('--port [port]', "the port to run parse-dashboard"); +program.option('--config [config]', "the path to the configuration file"); +program.option('--allowInsecureHTTP [allowInsecureHTTP]', 'set that flag when parse server is behind an HTTPS load balancer/proxy'); + +program.parse(process.argv); + +// collect the variables +var configFile = program.config || DEFAULT_DASHBOARD_CONFIG; +var port = program.port || process.env.PORT; +var allowInsecureHTTP = program.allowInsecureHTTP || process.env.PARSE_DASHBOARD_ALLOW_INSECURE_HTTP; + var basicAuth = require('basic-auth'); var jsonFile = require('json-file-plus'); var express = require('express'); @@ -14,7 +30,7 @@ var app = express(); app.use(express.static('Parse-Dashboard/public')); app.get('/parse-dashboard-config.json', function(req, res) { - jsonFile(__dirname + '/parse-dashboard-config.json') + jsonFile(configFile) .then(config => { var response = {apps: config.data.apps}; var users = config.data.users; @@ -28,7 +44,7 @@ app.get('/parse-dashboard-config.json', function(req, res) { req.connection.remoteAddress === '127.0.0.1' || req.connection.remoteAddress === '::ffff:127.0.0.1' || req.connection.remoteAddress === '::1'; - if (!requestIsLocal && !req.secure) { + if (!requestIsLocal && !req.secure && !allowInsecureHTTP) { //Disallow HTTP requests except on localhost, to prevent the master key from being transmitted in cleartext return res.send({ success: false, error: 'Parse Dashboard can only be remotely accessed via HTTPS' }); } @@ -85,4 +101,4 @@ app.get('/*', function(req, res) { }); // Start the server, listening to port 4040. -app.listen(process.env.PORT || 4040); +app.listen(port || 4040); diff --git a/README.md b/README.md index bee3f47128..283404e1ac 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,31 @@ If you want to require a username and password to access the dashboard, you can HTTPS and Basic Auth are mandatory if you are accessing the dashboard remotely instead of accessing it from `localhost`. +## Deploying in production + +If you're deploying to a provider like Heroku, or Google App Engine, the SSL endpoint is terminated early and handled by the provider and you may encounter this error `Parse Dashboard can only be remotely accessed via HTTPS`. + +:warning: :warning: Before going further, make sure your server **cannot** be reachable via **HTTP**. See the provider documentation for force HTTPS connections to your deployment. + +Set the environment variable to PARSE_DASHBOARD_ALLOW_INSECURE_HTTP=1 to tell parse server to skip the secure tests. + +To start your server use: + +`$ npm start` + + +Optionally you can use the command line arguments: + +`$ npm start -- --config path/to/config.json --port 8080 --allowInsecureHTTP=1` + +All paramters are optional and their default values are: + + + config: parse-dashboard/Parse-Dashboard/parse-dashboard-config.json + port: 4040 + allowInsecureHTTP: false + + ## Contributing We really want Parse to be yours, to see it grow and thrive in the open source community. Please see the [Contributing to Parse Dashboard guide](CONTRIBUTING.md). diff --git a/package.json b/package.json index 9877015f0b..4ec2e57bb3 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "dependencies": { "babel-runtime": "~5.8.25", "basic-auth": "^1.0.3", + "commander": "^2.9.0", "express": "^4.13.4", "history": "~1.9.1", "immutable": "~3.7.5", @@ -39,7 +40,9 @@ "build": "NODE_ENV=production webpack --config production.config.js && webpack --config PIG.config.js", "test": "NODE_PATH=./node_modules jest", "generate": "node scripts/generate.js", - "preinstall": "git update-index --skip-worktree Parse-Dashboard/parse-dashboard-config.json" + "preinstall": "git update-index --skip-worktree Parse-Dashboard/parse-dashboard-config.json", + "prestart": "webpack --config build.config.js --progress", + "start": "node ./Parse-Dashboard/index.js" }, "jest": { "testPathDirs": [