0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00
ghost/core/server/web/parent-app.js
Hannah Wolfe ce6745b6a1 Improved x-request-id handling
- Currently, we create a request ID for internal use if one isn't set & this is used in logs
- If a custom request ID is set via X-Request-ID header, this gets logged, however, we don't return this with the response
- Means that a custom ID gets lost on the way back out, and makes tracing requests through a system trickier
- This change ensures that if X-Request-ID is set on the request, it is also set on the response so that requests can be properly traced
- It's easy to set this in e.g. nginx so that the feature becomes available - Ghost doens't need to do this
- Note: also split request id handling out into new middleware
2019-12-04 16:13:35 +00:00

61 lines
1.6 KiB
JavaScript

var debug = require('ghost-ignition').debug('app'),
express = require('express'),
// App requires
config = require('../config'),
// middleware
compress = require('compression'),
netjet = require('netjet'),
// local middleware
ghostLocals = require('./middleware/ghost-locals'),
requestId = require('./middleware/request-id'),
logRequest = require('./middleware/log-request');
module.exports = function setupParentApp() {
debug('ParentApp setup start');
var 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(requestId);
parentApp.use(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(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('/ghost/api/v0.1/', require('./api/app')());
// ADMIN
parentApp.use('/ghost', require('./admin')());
// BLOG
parentApp.use(require('./site')());
debug('ParentApp setup end');
return parentApp;
};