Skip to content

Commit c0f745c

Browse files
committed
Merge pull request #58 from ParsePlatform/flovilmart.CLI
Adds commander CLI, improve remote deployments
2 parents cb8a8c4 + f16f3af commit c0f745c

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

Parse-Dashboard/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55
* This source code is licensed under the license found in the LICENSE file in
66
* the root directory of this source tree.
77
*/
8+
// Command line tool for npm start
9+
10+
var DEFAULT_DASHBOARD_CONFIG = __dirname + '/parse-dashboard-config.json';
11+
12+
var program = require("commander");
13+
program.option('--port [port]', "the port to run parse-dashboard");
14+
program.option('--config [config]', "the path to the configuration file");
15+
program.option('--allowInsecureHTTP [allowInsecureHTTP]', 'set that flag when parse server is behind an HTTPS load balancer/proxy');
16+
17+
program.parse(process.argv);
18+
19+
// collect the variables
20+
var configFile = program.config || DEFAULT_DASHBOARD_CONFIG;
21+
var port = program.port || process.env.PORT;
22+
var allowInsecureHTTP = program.allowInsecureHTTP || process.env.PARSE_DASHBOARD_ALLOW_INSECURE_HTTP;
23+
824
var basicAuth = require('basic-auth');
925
var jsonFile = require('json-file-plus');
1026
var express = require('express');
@@ -14,7 +30,7 @@ var app = express();
1430
app.use(express.static('Parse-Dashboard/public'));
1531

1632
app.get('/parse-dashboard-config.json', function(req, res) {
17-
jsonFile(__dirname + '/parse-dashboard-config.json')
33+
jsonFile(configFile)
1834
.then(config => {
1935
var response = {apps: config.data.apps};
2036
var users = config.data.users;
@@ -28,7 +44,7 @@ app.get('/parse-dashboard-config.json', function(req, res) {
2844
req.connection.remoteAddress === '127.0.0.1' ||
2945
req.connection.remoteAddress === '::ffff:127.0.0.1' ||
3046
req.connection.remoteAddress === '::1';
31-
if (!requestIsLocal && !req.secure) {
47+
if (!requestIsLocal && !req.secure && !allowInsecureHTTP) {
3248
//Disallow HTTP requests except on localhost, to prevent the master key from being transmitted in cleartext
3349
return res.send({ success: false, error: 'Parse Dashboard can only be remotely accessed via HTTPS' });
3450
}
@@ -85,4 +101,4 @@ app.get('/*', function(req, res) {
85101
});
86102

87103
// Start the server, listening to port 4040.
88-
app.listen(process.env.PORT || 4040);
104+
app.listen(port || 4040);

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,31 @@ If you want to require a username and password to access the dashboard, you can
7878

7979
HTTPS and Basic Auth are mandatory if you are accessing the dashboard remotely instead of accessing it from `localhost`.
8080

81+
## Deploying in production
82+
83+
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`.
84+
85+
: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.
86+
87+
Set the environment variable to PARSE_DASHBOARD_ALLOW_INSECURE_HTTP=1 to tell parse server to skip the secure tests.
88+
89+
To start your server use:
90+
91+
`$ npm start`
92+
93+
94+
Optionally you can use the command line arguments:
95+
96+
`$ npm start -- --config path/to/config.json --port 8080 --allowInsecureHTTP=1`
97+
98+
All paramters are optional and their default values are:
99+
100+
101+
config: parse-dashboard/Parse-Dashboard/parse-dashboard-config.json
102+
port: 4040
103+
allowInsecureHTTP: false
104+
105+
81106
## Contributing
82107

83108
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).

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"dependencies": {
44
"babel-runtime": "~5.8.25",
55
"basic-auth": "^1.0.3",
6+
"commander": "^2.9.0",
67
"express": "^4.13.4",
78
"history": "~1.9.1",
89
"immutable": "~3.7.5",
@@ -39,7 +40,9 @@
3940
"build": "NODE_ENV=production webpack --config production.config.js && webpack --config PIG.config.js",
4041
"test": "NODE_PATH=./node_modules jest",
4142
"generate": "node scripts/generate.js",
42-
"preinstall": "git update-index --skip-worktree Parse-Dashboard/parse-dashboard-config.json"
43+
"preinstall": "git update-index --skip-worktree Parse-Dashboard/parse-dashboard-config.json",
44+
"prestart": "webpack --config build.config.js --progress",
45+
"start": "node ./Parse-Dashboard/index.js"
4346
},
4447
"jest": {
4548
"testPathDirs": [

0 commit comments

Comments
 (0)