Add server log

This commit is contained in:
soruly 2022-06-18 07:45:45 +00:00
parent f159f2342d
commit fdac0a0c14
No known key found for this signature in database
GPG Key ID: EF971E90F3D2521F
1 changed files with 17 additions and 0 deletions

View File

@ -2,6 +2,7 @@ import "dotenv/config.js";
import fs from "fs-extra";
import path from "path";
import crypto from "crypto";
import { performance } from "perf_hooks";
import express from "express";
import rateLimit from "express-rate-limit";
import getIpInfo from "./src/get-ip-info.js";
@ -58,6 +59,22 @@ app.use(
})
);
app.use((req, res, next) => {
const startTime = performance.now();
console.log("=>", new Date().toISOString(), req.ip, req.path);
res.on("finish", () => {
console.log(
"<=",
new Date().toISOString(),
req.ip,
req.path,
res.statusCode,
`${(performance.now() - startTime).toFixed(0)}ms`
);
});
next();
});
app.get(/[^\/]+\.[^\/]+$/, express.static("./static", { maxAge: 1000 * 60 * 60 * 24 }));
app.delete("/", (req, res) => {