0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00
ghost/core/server/web/parent/app.js
Hannah Wolfe 332beaaf90
Moved "vhost-utils" to config helpers
- These are simple functions that get data from config in a specific format
- They are also used by the topmost part of the application
- Config helpers seems like a reasonable fit to get them out of the web folder
- Functions have also been renamed to try to get them to make more sense
2021-11-17 08:37:08 +00:00

40 lines
1.3 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');
module.exports = function setupParentApp(options = {}) {
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
// ADMIN + API
const backendApp = require('./backend')();
parentApp.use(vhost(config.getBackendMountPath(), backendApp));
// SITE + MEMBERS
const frontendApp = require('./frontend')(options);
parentApp.use(vhost(config.getFrontendMountPath(), frontendApp));
debug('ParentApp setup end');
return parentApp;
};