mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-17 21:41:49 +03:00
7bcccc71dc
refs #9178 - move express apps to one place (called `web`) - requires https://github.com/TryGhost/Ghost-Admin/pull/923 - any further improvements are not part of this PR - this PR just moves the files and ensures the paths are up-to-date
31 lines
855 B
JavaScript
31 lines
855 B
JavaScript
var uuid = require('uuid'),
|
|
logging = require('../../logging');
|
|
|
|
/**
|
|
* @TODO:
|
|
* - move middleware to ignition?
|
|
*/
|
|
module.exports = function logRequest(req, res, next) {
|
|
var startTime = Date.now(),
|
|
requestId = req.get('X-Request-ID') || uuid.v1();
|
|
|
|
function logResponse() {
|
|
res.responseTime = (Date.now() - startTime) + 'ms';
|
|
req.requestId = requestId;
|
|
req.userId = req.user ? (req.user.id ? req.user.id : req.user) : null;
|
|
|
|
if (req.err && req.err.statusCode !== 404) {
|
|
logging.error({req: req, res: res, err: req.err});
|
|
} else {
|
|
logging.info({req: req, res: res});
|
|
}
|
|
|
|
res.removeListener('finish', logResponse);
|
|
res.removeListener('close', logResponse);
|
|
}
|
|
|
|
res.on('finish', logResponse);
|
|
res.on('close', logResponse);
|
|
next();
|
|
};
|