[Snow Team] express-types: auto-commit work
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user