swaf/src/components/LogRequestsComponent.ts

21 lines
640 B
TypeScript
Raw Normal View History

2020-04-22 15:52:17 +02:00
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> {
}
}