mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
refs https://github.com/TryGhost/Toolbox/issues/135 - Without sensible defaults the web app was not initializing either the backend nor the frontned parts of the application. Fixed the defaults so the problem doesn't happen again and optimized mock-express-style initialization to only initialize the frontend routing
49 lines
1.6 KiB
JavaScript
49 lines
1.6 KiB
JavaScript
const debug = require('@tryghost/debug')('web:parent');
|
|
const config = require('../../../shared/config');
|
|
const express = require('../../../shared/express');
|
|
const compress = require('compression');
|
|
const mw = require('./middleware');
|
|
const vhost = require('@tryghost/vhost-middleware');
|
|
|
|
/**
|
|
* @param {Object} options
|
|
* @param {Boolean} [options.start]
|
|
* @param {Boolean} [options.withBackend]
|
|
* @param {Boolean} [options.withFrontend]
|
|
*/
|
|
module.exports = function setupParentApp({start, withFrontend = true, withBackend = true}) {
|
|
debug('ParentApp setup start');
|
|
const parentApp = express('parent');
|
|
|
|
parentApp.use(mw.requestId);
|
|
parentApp.use(mw.logRequest);
|
|
|
|
// Register event emmiter on req/res to trigger cache invalidation webhook event
|
|
parentApp.use(mw.emitEvents);
|
|
|
|
// enabled gzip compression by default
|
|
if (config.get('compress') !== false) {
|
|
parentApp.use(compress());
|
|
}
|
|
|
|
// This sets global res.locals which are needed everywhere
|
|
// @TODO: figure out if this is really needed everywhere? Is it not frontend only...
|
|
parentApp.use(mw.ghostLocals);
|
|
|
|
// Mount the express apps on the parentApp
|
|
|
|
if (withBackend) {
|
|
debug('Mounting bakcend: ADMIN + API');
|
|
const backendApp = require('./backend')();
|
|
parentApp.use(vhost(config.getBackendMountPath(), backendApp));
|
|
}
|
|
|
|
if (withFrontend) {
|
|
debug('Mounting frontend: SITE + MEMBERS');
|
|
const frontendApp = require('./frontend')({start});
|
|
parentApp.use(vhost(config.getFrontendMountPath(), frontendApp));
|
|
}
|
|
debug('ParentApp setup end');
|
|
|
|
return parentApp;
|
|
};
|