mirror of
https://github.com/kmitresse/Compo-Service-Log-Project.git
synced 2026-05-13 17:11:49 +00:00
24 lines
542 B
TypeScript
24 lines
542 B
TypeScript
import { NextFunction, Request, Response } from "express";
|
|
import { Log } from "../entity/Log";
|
|
import { TypeOrmDataSource } from "../TypeOrmDataSource";
|
|
|
|
export default async function logger(
|
|
req: Request,
|
|
res: Response,
|
|
next: NextFunction
|
|
) {
|
|
console.info(`[${req.method}] ${req.url}`);
|
|
|
|
if (req.path === "/randomize") {
|
|
// Put the log into the database
|
|
const log: Log = new Log(
|
|
req.url,
|
|
req.method as any,
|
|
JSON.stringify(req.body)
|
|
);
|
|
await TypeOrmDataSource.manager.save(log);
|
|
}
|
|
|
|
next();
|
|
}
|