This commit is contained in:
seb
2026-06-23 11:04:07 +02:00
commit 667f498573
19 changed files with 4299 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
import chalk from 'chalk';
export const loggerMiddleware = (req, res, next) => {
const start = Date.now();
res.on('finish', () => {
const duration = Date.now() - start;
const method = chalk.bold.blue(req.method.padEnd(7));
const url = req.originalUrl;
let status = res.statusCode;
if (status >= 500) status = chalk.red(status);
else if (status >= 400) status = chalk.yellow(status);
else if (status >= 300) status = chalk.cyan(status);
else status = chalk.green(status);
console.log(`${method} ${url} ${status} ${chalk.gray(`(${duration}ms)`)}`);
});
next();
};