Repository URL to install this package:
|
Version:
0.0.3 ▾
|
import { isFunction } from 'exotic'
import { NextFunction, ExpressResponse, ExpressRequest } from './typings'
import { fromNodeHttpResponseToFetchResponse, fromReqToObj } from './logging'
export function logHttpMiddleware(req: ExpressRequest, res: ExpressResponse, next?: NextFunction) {
const obj = fromReqToObj(req)
req.log.info(obj)
res.on('finish', () => {
const serializedRes = fromNodeHttpResponseToFetchResponse(res)
req.log.info('responded')
req.log.info(serializedRes)
})
if (isFunction(next) === true) {
next()
}
}