Update logging
This commit is contained in:
parent
fdac0a0c14
commit
8282f19c3b
49
server.js
49
server.js
|
@ -23,11 +23,40 @@ app.set("view engine", "ejs");
|
|||
app.set("views", path.resolve("."));
|
||||
|
||||
app.use((req, res, next) => {
|
||||
if (BLACKLIST_UA && req.headers["user-agent"]?.match(new RegExp(`(${BLACKLIST_UA})`, "i")))
|
||||
return;
|
||||
const { ASN, country } = getIpInfo(req.ip);
|
||||
res.locals.ASN = ASN;
|
||||
res.locals.country = country;
|
||||
next();
|
||||
});
|
||||
|
||||
app.use((req, res, next) => {
|
||||
const startTime = performance.now();
|
||||
console.log(
|
||||
"=>",
|
||||
new Date().toISOString(),
|
||||
req.ip,
|
||||
res.locals.country.isoCode,
|
||||
res.locals.ASN.autonomousSystemNumber,
|
||||
req.path
|
||||
);
|
||||
res.on("finish", () => {
|
||||
console.log(
|
||||
"<=",
|
||||
new Date().toISOString(),
|
||||
req.ip,
|
||||
res.locals.country.isoCode,
|
||||
res.locals.ASN.autonomousSystemNumber,
|
||||
req.path,
|
||||
res.statusCode,
|
||||
`${(performance.now() - startTime).toFixed(0)}ms`
|
||||
);
|
||||
});
|
||||
next();
|
||||
});
|
||||
|
||||
app.use((req, res, next) => {
|
||||
if (BLACKLIST_UA && req.headers["user-agent"]?.match(new RegExp(`(${BLACKLIST_UA})`, "i")))
|
||||
return;
|
||||
if (WHITELIST_COUNTRY && !WHITELIST_COUNTRY.split("|").includes(res.locals.country.isoCode))
|
||||
return;
|
||||
next();
|
||||
|
@ -59,22 +88,6 @@ 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