[Snow Team] express-types: auto-commit work

This commit is contained in:
yml
2026-05-21 22:57:48 +08:00
parent c72396ca15
commit 0e6bf88beb
10 changed files with 639 additions and 463 deletions
+12 -4
View File
@@ -1,6 +1,11 @@
import type { Request, Response, NextFunction } from "express";
import { createRequestId, logInfo } from "../utils/logger.js";
export function accessLogMiddleware(req, res, next) {
export function accessLogMiddleware(
req: Request,
res: Response,
next: NextFunction
): void {
const startedAt = Date.now();
const requestId = resolveRequestId(req);
@@ -32,12 +37,15 @@ export function accessLogMiddleware(req, res, next) {
next();
}
function resolveRequestId(req) {
function resolveRequestId(req: Request): string {
const fromHeader = String(req.headers["x-request-id"] || "").trim();
return fromHeader || createRequestId("req");
}
function shouldSkipAccessLog(originalUrl, statusCode) {
function shouldSkipAccessLog(originalUrl: string, statusCode: number): boolean {
const pathname = String(originalUrl || "").split("?")[0];
return ["/health", "/health/live", "/health/ready"].includes(pathname) && Number(statusCode) < 400;
return (
["/health", "/health/live", "/health/ready"].includes(pathname) &&
Number(statusCode) < 400
);
}