Skip to content

Commit 561196f

Browse files
Vortec4800drew-gross
authored andcommitted
Added SSL Support to Dashboard (#306)
1 parent e49c5be commit 561196f

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

Parse-Dashboard/index.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ program.option('--host [host]', 'the host to run parse-dashboard');
2222
program.option('--port [port]', 'the port to run parse-dashboard');
2323
program.option('--mountPath [mountPath]', 'the mount path to run parse-dashboard');
2424
program.option('--allowInsecureHTTP [allowInsecureHTTP]', 'set this flag when you are running the dashboard behind an HTTPS load balancer or proxy with early SSL termination.');
25+
program.option('--sslKey [sslKey]', 'the path to the SSL private key.');
26+
program.option('--sslCert [sslCert]', 'the path to the SSL certificate.');
2527

2628
program.parse(process.argv);
2729

@@ -39,6 +41,8 @@ let configAppId = program.appId || process.env.PARSE_DASHBOARD_APP_ID;
3941
let configAppName = program.appName || process.env.PARSE_DASHBOARD_APP_NAME;
4042
let configUserId = program.userId || process.env.PARSE_DASHBOARD_USER_ID;
4143
let configUserPassword = program.userPassword || process.env.PARSE_DASHBOARD_USER_PASSWORD;
44+
let configSSLKey = program.sslKey || process.env.PARSE_DASHBOARD_SSL_KEY;
45+
let configSSLCert = program.sslCert || process.env.PARSE_DASHBOARD_SSL_CERT;
4246
if (!program.config && !process.env.PARSE_DASHBOARD_CONFIG) {
4347
if (configServerURL && configMasterKey && configAppId) {
4448
configFromCLI = {
@@ -102,10 +106,24 @@ p.then(config => {
102106
const app = express();
103107

104108
app.use(mountPath, parseDashboard(config.data, allowInsecureHTTP));
105-
// Start the server.
106-
const server = app.listen(port, host, function () {
107-
console.log(`The dashboard is now available at http://${server.address().address}:${server.address().port}${mountPath}`);
108-
});
109+
if(!configSSLKey || !configSSLCert){
110+
// Start the server.
111+
const server = app.listen(port, host, function () {
112+
console.log(`The dashboard is now available at http://${server.address().address}:${server.address().port}${mountPath}`);
113+
});
114+
} else {
115+
// Start the server using SSL.
116+
var fs = require('fs');
117+
var privateKey = fs.readFileSync(configSSLKey);
118+
var certificate = fs.readFileSync(configSSLCert);
119+
120+
const server = require('https').createServer({
121+
key: privateKey,
122+
cert: certificate
123+
}, app).listen(port, host, function () {
124+
console.log(`The dashboard is now available at https://${server.address().address}:${server.address().port}${mountPath}`);
125+
});
126+
}
109127
}, error => {
110128
if (error instanceof SyntaxError) {
111129
console.log('Your config file contains invalid JSON. Exiting.');

0 commit comments

Comments
 (0)