2015-05-28 18:16:09 +03:00
|
|
|
// # Ghost Startup
|
|
|
|
// Orchestrates the startup of Ghost when run from command line.
|
2017-02-17 18:27:02 +03:00
|
|
|
|
2020-04-25 23:06:33 +03:00
|
|
|
const startTime = Date.now();
|
|
|
|
const debug = require('ghost-ignition').debug('boot:index');
|
2020-04-25 22:53:58 +03:00
|
|
|
// Sentry must be initialised early on
|
|
|
|
const sentry = require('./core/shared/sentry');
|
2017-02-17 18:27:02 +03:00
|
|
|
|
|
|
|
debug('First requires...');
|
|
|
|
|
2020-04-25 23:06:33 +03:00
|
|
|
const ghost = require('./core');
|
2017-02-17 18:27:02 +03:00
|
|
|
|
|
|
|
debug('Required ghost');
|
|
|
|
|
2020-04-25 22:53:58 +03:00
|
|
|
const express = require('./core/shared/express');
|
2020-04-30 22:26:12 +03:00
|
|
|
const {logging} = require('./core/server/lib/common');
|
2020-04-25 23:06:33 +03:00
|
|
|
const urlService = require('./core/frontend/services/url');
|
2020-05-01 21:29:42 +03:00
|
|
|
// This is what listen gets called on, it needs to be a full Express App
|
|
|
|
const ghostApp = express('ghost');
|
2016-06-03 11:06:18 +03:00
|
|
|
|
2020-04-25 22:53:58 +03:00
|
|
|
// Use the request handler at the top level
|
|
|
|
// @TODO: decide if this should be here or in parent App - should it come after request id mw?
|
2020-04-27 18:54:31 +03:00
|
|
|
ghostApp.use(sentry.requestHandler);
|
2020-01-29 15:09:21 +03:00
|
|
|
|
2016-10-03 11:33:14 +03:00
|
|
|
debug('Initialising Ghost');
|
2020-04-25 23:06:33 +03:00
|
|
|
|
2014-09-19 20:17:58 +04:00
|
|
|
ghost().then(function (ghostServer) {
|
2015-05-28 18:16:09 +03:00
|
|
|
// Mount our Ghost instance on our desired subdirectory path if it exists.
|
2020-04-27 18:54:31 +03:00
|
|
|
ghostApp.use(urlService.utils.getSubdir(), ghostServer.rootApp);
|
2014-08-24 00:42:44 +04:00
|
|
|
|
2016-10-03 11:33:14 +03:00
|
|
|
debug('Starting Ghost');
|
2015-05-28 18:16:09 +03:00
|
|
|
// Let Ghost handle starting our server instance.
|
2020-04-27 18:54:31 +03:00
|
|
|
return ghostServer.start(ghostApp)
|
2018-07-27 16:19:39 +03:00
|
|
|
.then(function afterStart() {
|
2020-04-30 22:26:12 +03:00
|
|
|
logging.info('Ghost boot', (Date.now() - startTime) / 1000 + 's');
|
2018-07-27 16:19:39 +03:00
|
|
|
});
|
2017-01-26 15:12:00 +03:00
|
|
|
}).catch(function (err) {
|
2020-04-30 22:26:12 +03:00
|
|
|
logging.error(err);
|
2018-08-22 14:28:31 +03:00
|
|
|
setTimeout(() => {
|
|
|
|
process.exit(-1);
|
|
|
|
}, 100);
|
2014-08-19 20:36:46 +04:00
|
|
|
});
|