Ghost/core/server/web/parent-app.js
anaplian c539d39875 🐛 Fixed missing 404 for unknown API routes (#10070)
closes #10020

* Append trailing slash to version path
2018-11-26 16:35:38 +07:00

53 lines
1.4 KiB
JavaScript

const debug = require('ghost-ignition').debug('web:parent');
const express = require('express');
const config = require('../config');
const compress = require('compression');
const netjet = require('netjet');
const shared = require('./shared');
module.exports = function setupParentApp(options = {}) {
debug('ParentApp setup start');
const parentApp = express();
// ## Global settings
// Make sure 'req.secure' is valid for proxied requests
// (X-Forwarded-Proto header will be checked, if present)
parentApp.enable('trust proxy');
parentApp.use(shared.middlewares.logRequest);
// enabled gzip compression by default
if (config.get('compress') !== false) {
parentApp.use(compress());
}
// Preload link headers
if (config.get('preloadHeaders')) {
parentApp.use(netjet({
cache: {
max: config.get('preloadHeaders')
}
}));
}
// This sets global res.locals which are needed everywhere
parentApp.use(shared.middlewares.ghostLocals);
// Mount the apps on the parentApp
// API
// @TODO: finish refactoring the API app
parentApp.use('/ghost/api', require('./api')());
// ADMIN
parentApp.use('/ghost', require('./admin')());
// BLOG
parentApp.use(require('./site')(options));
debug('ParentApp setup end');
return parentApp;
};