Skip to content

Adds commander CLI, improve remote deployments #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions Parse-Dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand All @@ -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' });
}
Expand Down Expand Up @@ -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);
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": [
Expand Down