const logger = require('../utils/logger.js') // TODO: use this middleware in all modules module.exports = function (options) { const loggableKeywords = options ? options.loggableKeywords : undefined return function (req, res, next) { res.on('finish', function () { if (req.url.includes('_next/static')) { return } const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress const hostname = req.hostname.replace('www.', '').split('.')[0] // TODO: merge req.url and req.hostname checking // TODO: regexp includes checking let toLog = loggableKeywords && loggableKeywords.some((x) => { return req.url.includes(x) }) if (hostname.includes('dataeditor')) { toLog = true } logger.LogReq(req, true, res.statusCode) if (toLog) { logger.LogReq(req) } if (res.statusCode !== 404) { logger.LogStat(req.url, ip) } }) next() } }