-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Adds support for using Parse Dashboard as Express middleware #209
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright (c) 2016-present, Parse, LLC | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the LICENSE file in | ||
* the root directory of this source tree. | ||
*/ | ||
"use strict"; | ||
const packageJson = require('package-json'); | ||
const basicAuth = require('basic-auth'); | ||
const path = require('path'); | ||
const jsonFile = require('json-file-plus'); | ||
|
||
var ParseDashboard = require('../index.js'); | ||
// Command line tool for npm start | ||
|
||
const program = require('commander'); | ||
program.option('--appId [appId]', 'the app Id of the app you would like to manage.'); | ||
program.option('--masterKey [masterKey]', 'the master key of the app you would like to manage.'); | ||
program.option('--serverURL [serverURL]', 'the server url of the app you would like to manage.'); | ||
program.option('--appName [appName]', 'the name of the app you would like to manage. Optional.'); | ||
program.option('--config [config]', 'the path to the configuration file'); | ||
program.option('--port [port]', 'the port to run parse-dashboard'); | ||
program.option('--allowInsecureHTTP [allowInsecureHTTP]', 'set this flag when you are running the dashboard behind an HTTPS load balancer or proxy with early SSL termination.'); | ||
|
||
program.parse(process.argv); | ||
|
||
|
||
const port = program.port || process.env.PORT || 4040; | ||
const allowInsecureHTTP = program.allowInsecureHTTP || process.env.PARSE_DASHBOARD_ALLOW_INSECURE_HTTP; | ||
|
||
let explicitConfigFileProvided = !!program.config; | ||
let configFile = null; | ||
let configFromCLI = null; | ||
let configServerURL = program.serverURL || process.env.PARSE_DASHBOARD_SERVER_URL; | ||
let configMasterKey = program.masterKey || process.env.PARSE_DASHBOARD_MASTER_KEY; | ||
let configAppId = program.appId || process.env.PARSE_DASHBOARD_APP_ID; | ||
let configAppName = program.appName || process.env.PARSE_DASHBOARD_APP_NAME; | ||
let configUserId = program.userId || process.env.PARSE_DASHBOARD_USER_ID; | ||
let configUserPassword = program.userPassword || process.env.PARSE_DASHBOARD_USER_PASSWORD; | ||
if (!program.config && !process.env.PARSE_DASHBOARD_CONFIG) { | ||
if (configServerURL && configMasterKey && configAppId) { | ||
configFromCLI = { | ||
data: { | ||
apps: [ | ||
{ | ||
appId: configAppId, | ||
serverURL: configServerURL, | ||
masterKey: configMasterKey, | ||
appName: configAppName, | ||
}, | ||
] | ||
} | ||
}; | ||
if (configUserId && configUserPassword) { | ||
configFromCLI.data.users = [ | ||
{ | ||
user: configUserId, | ||
pass: configUserPassword, | ||
} | ||
]; | ||
} | ||
} else if (!configServerURL && !configMasterKey && !configAppName) { | ||
configFile = path.join(__dirname, '/../parse-dashboard-config.json'); | ||
} | ||
} else if (!program.config && process.env.PARSE_DASHBOARD_CONFIG) { | ||
configFromCLI = { | ||
data: JSON.parse(process.env.PARSE_DASHBOARD_CONFIG) | ||
}; | ||
} else { | ||
configFile = program.config; | ||
if (program.appId || program.serverURL || program.masterKey || program.appName) { | ||
console.log('You must provide either a config file or required CLI options (app ID, Master Key, and server URL); not both.'); | ||
process.exit(3); | ||
} | ||
} | ||
|
||
|
||
|
||
let p = null; | ||
if (configFile) { | ||
p = jsonFile(configFile); | ||
} else if (configFromCLI) { | ||
p = Promise.resolve(configFromCLI); | ||
} else { | ||
//Failed to load default config file. | ||
console.log('You must provide either a config file or an app ID, Master Key, and server URL. See parse-dashboard --help for details.'); | ||
process.exit(4); | ||
} | ||
|
||
p.then(config => { | ||
config.data.port = port; | ||
ParseDashboard.runServer(config.data); | ||
}, error => { | ||
if (error instanceof SyntaxError) { | ||
console.log('Your config file contains invalid JSON. Exiting.'); | ||
process.exit(1); | ||
} else if (error.code === 'ENOENT') { | ||
if (explicitConfigFileProvided) { | ||
console.log('Your config file is missing. Exiting.'); | ||
process.exit(2); | ||
} else { | ||
console.log('You must provide either a config file or required CLI options (app ID, Master Key, and server URL); not both.'); | ||
process.exit(3); | ||
} | ||
} else { | ||
console.log('There was a problem with your config. Exiting.'); | ||
process.exit(-1); | ||
} | ||
}) | ||
.catch(error => { | ||
console.log('There was a problem loading the dashboard. Exiting.'); | ||
process.exit(-1); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env node | ||
require('../Parse-Dashboard'); | ||
require('../Parse-Dashboard/cli'); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't work as we don't pass it through babel AFAIK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code doesn't pass through babel, but Node.js supports some features of ECMAScript 6 (including classes, albeit only in strict mode) without the need for babel compilation. (See: https://nodejs.org/en/docs/es6/)