Ghost/index.js
Hannah Wolfe 0fe0e09d62 Moved express init + sentry to a shared util
- added core/shared to watched folders in grunt
- moved sentry to shared
- moved express initialisation to a shared file
- always set trust proxy + sentry error handler
- use this new express init everywhere, and remove duplicate trust proxy and sentry error handler code
2020-04-27 18:17:50 +01:00

42 lines
1.3 KiB
JavaScript

// # Ghost Startup
// Orchestrates the startup of Ghost when run from command line.
const startTime = Date.now();
const debug = require('ghost-ignition').debug('boot:index');
// Sentry must be initialised early on
const sentry = require('./core/shared/sentry');
debug('First requires...');
const ghost = require('./core');
debug('Required ghost');
const express = require('./core/shared/express');
const common = require('./core/server/lib/common');
const urlService = require('./core/frontend/services/url');
const ghostApp = express();
// 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?
ghostApp.use(sentry.requestHandler);
debug('Initialising Ghost');
ghost().then(function (ghostServer) {
// Mount our Ghost instance on our desired subdirectory path if it exists.
ghostApp.use(urlService.utils.getSubdir(), ghostServer.rootApp);
debug('Starting Ghost');
// Let Ghost handle starting our server instance.
return ghostServer.start(ghostApp)
.then(function afterStart() {
common.logging.info('Ghost boot', (Date.now() - startTime) / 1000 + 's');
});
}).catch(function (err) {
common.logging.error(err);
setTimeout(() => {
process.exit(-1);
}, 100);
});