common.js
908 Bytes
const MODULE_NAME = 'MIDDLEWARES';
const uuidv1 = require('uuid/v1');
const uniqid = require('uniqid');
const config = require('komodo-sdk/config');
const logger = require('tektrans-logger');
module.exports = function common(req, res, next) {
if (req.url.search('/favicon.ico') === 0) {
res.sendStatus(404);
return;
}
res.locals.xid = config.xid_from_uuid ? uuidv1()
: uniqid();
res.locals.x_http_request_ts = new Date();
logger.info(`${MODULE_NAME}.COMMON B6257542: Got a request`, {
xid: res.locals.xid,
pid: process.pid,
subsystem: res.locals.httpgetx_subsystem,
userAgent: req.get('user-agent'),
requesterIp: req.ip,
method: req.method,
requestContentType: req.get('content-type'),
path: req.path,
url: req.url,
qs: req.query,
body: req.body,
});
next();
};