This repository was archived by the owner on Nov 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
44 lines (37 loc) · 1.29 KB
/
main.js
File metadata and controls
44 lines (37 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* main.js
*
* A loader program to call some functions in server.js and then launch the Ghost process.
* This is split out from server.js to make testing easier.
*/
// Built-in dependencies
const fs = require('fs');
const url = require('url');
// Third-party dependencies
const server = require('./server.js');
// -------- Start main program --------
try {
var node_env = 'development';
if (!!process.env.NODE_ENV) {
node_env = process.env.NODE_ENV;
}
console.log('NODE_ENV=' + node_env + '\n');
// Generate and write config.production.json file
const configData = JSON.stringify(server.generateGhostConfig(), null, 2);
fs.writeFileSync(
'config.' + node_env + '.json',
configData,
'utf8'
);
if (process.env.DEBUG === 'true') {
console.log('DEBUG OUTPUT: Config dump:\n' + configData + '\n');
}
// This will launch an async process to start the express server and Ghost.
// It feels slightly hacky? But it seems to be fine, and I prefer it to launching a child process
require('./current/index.js');
} catch (err) {
// Handle errors in the promise chain.
// Just log it and exit??
console.log('Encountered error starting Ghost: ' + (err ? err.toString() : '<unknown error>'));
process.exit(1);
}