21 lines
640 B
TypeScript
21 lines
640 B
TypeScript
|
import ApplicationComponent from "../ApplicationComponent";
|
||
|
import onFinished from "on-finished";
|
||
|
import Logger from "../Logger";
|
||
|
import {Express, Router} from "express";
|
||
|
|
||
|
export default class LogRequestsComponent extends ApplicationComponent<void> {
|
||
|
public async start(app: Express, router: Router): Promise<void> {
|
||
|
router.use((req, res, next) => {
|
||
|
onFinished(res, (err) => {
|
||
|
if (!err) {
|
||
|
Logger.info(`${req.method} ${req.originalUrl} - ${res.statusCode}`);
|
||
|
}
|
||
|
});
|
||
|
next();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public async stop(): Promise<void> {
|
||
|
}
|
||
|
|
||
|
}
|