Add server log
This commit is contained in:
parent
f159f2342d
commit
fdac0a0c14
17
server.js
17
server.js
|
@ -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) => {
|
||||
|
|
Loading…
Reference in New Issue