Added request logging

This commit is contained in:
Mark van Renswoude 2021-08-18 18:50:47 +02:00
parent 67909bc71a
commit 796d519c31

View File

@ -57,8 +57,18 @@ async function asyncMain()
const app = express(); const app = express();
const logMiddleware = (req, res, next) =>
{
// TODO merge with api.js' version
const ip = req.headers['x-forwarded-for'] || req.ip;
logger.verbose(`[${ip}] ${req.path} (body = ${JSON.stringify(req.body)})`);
next()
}
app.use(express.json()); app.use(express.json());
app.use(express.urlencoded({ extended: false })); app.use(express.urlencoded({ extended: false }));
app.use(logMiddleware);
app.use('/api', container.ApiRoutes.createRouter(express)); app.use('/api', container.ApiRoutes.createRouter(express));
app.use('/', express.static('frontend/dist')); app.use('/', express.static('frontend/dist'));