parse-dashboard 3.1.2 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Parse-Dashboard/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// Command line tool for npm start
|
|
9
9
|
'use strict'
|
|
10
10
|
const path = require('path');
|
|
11
|
-
const
|
|
11
|
+
const fs = require('fs');
|
|
12
12
|
const express = require('express');
|
|
13
13
|
const parseDashboard = require('./app');
|
|
14
14
|
const CLIHelper = require('./CLIHelper.js');
|
|
@@ -126,74 +126,72 @@ if (!program.config && !process.env.PARSE_DASHBOARD_CONFIG) {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
let
|
|
129
|
+
let config = null;
|
|
130
130
|
let configFilePath = null;
|
|
131
131
|
if (configFile) {
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
try {
|
|
133
|
+
config = {
|
|
134
|
+
data: JSON.parse(fs.readFileSync(configFile, 'utf8'))
|
|
135
|
+
};
|
|
136
|
+
configFilePath = path.dirname(configFile);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (error instanceof SyntaxError) {
|
|
139
|
+
console.log('Your config file contains invalid JSON. Exiting.');
|
|
140
|
+
process.exit(1);
|
|
141
|
+
} else if (error.code === 'ENOENT') {
|
|
142
|
+
if (explicitConfigFileProvided) {
|
|
143
|
+
console.log('Your config file is missing. Exiting.');
|
|
144
|
+
process.exit(2);
|
|
145
|
+
} else {
|
|
146
|
+
console.log('You must provide either a config file or required CLI options (app ID, Master Key, and server URL); not both.');
|
|
147
|
+
process.exit(3);
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
console.log('There was a problem with your config. Exiting.');
|
|
151
|
+
process.exit(-1);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
134
154
|
} else if (configFromCLI) {
|
|
135
|
-
|
|
155
|
+
config = configFromCLI;
|
|
136
156
|
} else {
|
|
137
157
|
//Failed to load default config file.
|
|
138
158
|
console.log('You must provide either a config file or an app ID, Master Key, and server URL. See parse-dashboard --help for details.');
|
|
139
159
|
process.exit(4);
|
|
140
160
|
}
|
|
141
|
-
p.then(config => {
|
|
142
|
-
config.data.apps.forEach(app => {
|
|
143
|
-
if (!app.appName) {
|
|
144
|
-
app.appName = app.appId;
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
161
|
|
|
148
|
-
|
|
149
|
-
|
|
162
|
+
config.data.apps.forEach(app => {
|
|
163
|
+
if (!app.appName) {
|
|
164
|
+
app.appName = app.appId;
|
|
150
165
|
}
|
|
166
|
+
});
|
|
151
167
|
|
|
152
|
-
|
|
168
|
+
if (config.data.iconsFolder && configFilePath) {
|
|
169
|
+
config.data.iconsFolder = path.join(configFilePath, config.data.iconsFolder);
|
|
170
|
+
}
|
|
153
171
|
|
|
154
|
-
|
|
172
|
+
const app = express();
|
|
155
173
|
|
|
156
|
-
|
|
157
|
-
let dashboardOptions = { allowInsecureHTTP, cookieSessionSecret, dev };
|
|
158
|
-
app.use(mountPath, parseDashboard(config.data, dashboardOptions));
|
|
159
|
-
let server;
|
|
160
|
-
if(!configSSLKey || !configSSLCert){
|
|
161
|
-
// Start the server.
|
|
162
|
-
server = app.listen(port, host, function () {
|
|
163
|
-
console.log(`The dashboard is now available at http://${server.address().address}:${server.address().port}${mountPath}`);
|
|
164
|
-
});
|
|
165
|
-
} else {
|
|
166
|
-
// Start the server using SSL.
|
|
167
|
-
var fs = require('fs');
|
|
168
|
-
var privateKey = fs.readFileSync(configSSLKey);
|
|
169
|
-
var certificate = fs.readFileSync(configSSLCert);
|
|
174
|
+
if (allowInsecureHTTP || trustProxy || dev) app.enable('trust proxy');
|
|
170
175
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
process.exit(-1);
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
.catch(error => {
|
|
197
|
-
console.log('There was a problem loading the dashboard. Exiting.', error);
|
|
198
|
-
process.exit(-1);
|
|
199
|
-
});
|
|
176
|
+
config.data.trustProxy = trustProxy;
|
|
177
|
+
let dashboardOptions = { allowInsecureHTTP, cookieSessionSecret, dev };
|
|
178
|
+
app.use(mountPath, parseDashboard(config.data, dashboardOptions));
|
|
179
|
+
let server;
|
|
180
|
+
if(!configSSLKey || !configSSLCert){
|
|
181
|
+
// Start the server.
|
|
182
|
+
server = app.listen(port, host, function () {
|
|
183
|
+
console.log(`The dashboard is now available at http://${server.address().address}:${server.address().port}${mountPath}`);
|
|
184
|
+
});
|
|
185
|
+
} else {
|
|
186
|
+
// Start the server using SSL.
|
|
187
|
+
var privateKey = fs.readFileSync(configSSLKey);
|
|
188
|
+
var certificate = fs.readFileSync(configSSLCert);
|
|
189
|
+
|
|
190
|
+
server = require('https').createServer({
|
|
191
|
+
key: privateKey,
|
|
192
|
+
cert: certificate
|
|
193
|
+
}, app).listen(port, host, function () {
|
|
194
|
+
console.log(`The dashboard is now available at https://${server.address().address}:${server.address().port}${mountPath}`);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
handleSIGs(server);
|