mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
Add res.send to response logger
This commit is contained in:
@@ -10,12 +10,16 @@ export const requestLogger: Middleware = (req, _res, next) => {
|
||||
|
||||
export const responseLogger: Middleware = (req, res, next) => {
|
||||
const originalJson = res.json
|
||||
const originalSend = res.send
|
||||
const getLogString = (req: express.Request) =>
|
||||
`${res.statusCode} ${req.method} ${req.baseUrl}${req.url} ${req.user ? `Username: '${req.user.username}'` : ''}`
|
||||
res.json = function (body) {
|
||||
logger.info(getLogString(req))
|
||||
return originalJson.call(this, body)
|
||||
}
|
||||
|
||||
res.send = function (body) {
|
||||
logger.info(getLogString(req))
|
||||
return originalSend.call(this, body)
|
||||
}
|
||||
next()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user