mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
c795920cac
refs #9866 - exports `getApiPath` method from service/url/utils - uses `getApiPath` in web/parent-app to configure API paths for supported versions
56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
const debug = require('ghost-ignition').debug('app');
|
|
const express = require('express');
|
|
const config = require('../config');
|
|
const compress = require('compression');
|
|
const netjet = require('netjet');
|
|
const shared = require('./shared');
|
|
const urlUtils = require('../services/url/utils');
|
|
|
|
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
|
|
// @TODO: decide what to do with these paths - config defaults? config overrides?
|
|
parentApp.use(urlUtils.getApiPath('deprecated'), require('./api/v0.1/app')());
|
|
parentApp.use(urlUtils.getApiPath('active'), require('./api/v2/content/app')());
|
|
parentApp.use(urlUtils.getApiPath('active', true), require('./api/v2/admin/app')());
|
|
|
|
// ADMIN
|
|
parentApp.use('/ghost', require('./admin')());
|
|
|
|
// BLOG
|
|
parentApp.use(require('./site')(options));
|
|
|
|
debug('ParentApp setup end');
|
|
|
|
return parentApp;
|
|
};
|