Ghost/core/server/web/parent/middleware/request-id.js
Hannah Wolfe 8fe56852e0 Moved request-id mw into parent app
- Moved request-id from shared to parent as it is not shared
- This file is only used in one place, this updates the code structure to reflect this
- This is one of many similar changes needed to make it easier to refactor to the existing setup
2020-04-21 18:29:20 +01:00

19 lines
423 B
JavaScript

const uuid = require('uuid');
/**
* @TODO: move this middleware to ignition?
*/
module.exports = (req, res, next) => {
const requestId = req.get('X-Request-ID') || uuid.v4();
// Set a value for internal use
req.requestId = requestId;
// If the header was set on the request, return it on the response
if (req.get('X-Request-ID')) {
res.set('X-Request-ID', requestId);
}
next();
};