swaf/dist/components/LogRequestsComponent.js
2020-04-22 17:49:58 +02:00

31 lines
3.2 KiB
JavaScript

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import ApplicationComponent from "../ApplicationComponent";
import onFinished from "on-finished";
import Logger from "../Logger";
export default class LogRequestsComponent extends ApplicationComponent {
start(app, router) {
return __awaiter(this, void 0, void 0, function* () {
router.use((req, res, next) => {
onFinished(res, (err) => {
if (!err) {
Logger.info(`${req.method} ${req.originalUrl} - ${res.statusCode}`);
}
});
next();
});
});
}
stop() {
return __awaiter(this, void 0, void 0, function* () {
});
}
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTG9nUmVxdWVzdHNDb21wb25lbnQuanMiLCJzb3VyY2VSb290IjoiLi8iLCJzb3VyY2VzIjpbImNvbXBvbmVudHMvTG9nUmVxdWVzdHNDb21wb25lbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsT0FBTyxvQkFBb0IsTUFBTSx5QkFBeUIsQ0FBQztBQUMzRCxPQUFPLFVBQVUsTUFBTSxhQUFhLENBQUM7QUFDckMsT0FBTyxNQUFNLE1BQU0sV0FBVyxDQUFDO0FBRy9CLE1BQU0sQ0FBQyxPQUFPLE9BQU8sb0JBQXFCLFNBQVEsb0JBQTBCO0lBQzNELEtBQUssQ0FBQyxHQUFZLEVBQUUsTUFBYzs7WUFDM0MsTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQUFDLEdBQUcsRUFBRSxHQUFHLEVBQUUs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