7 lines
300 B
TypeScript
7 lines
300 B
TypeScript
import { randomUUID } from "node:crypto";
|
|
|
|
export function requestIdFrom(request: { headers: Record<string, string | string[] | undefined> }) {
|
|
const header = request.headers["x-request-id"];
|
|
return typeof header === "string" && /^[a-zA-Z0-9._:-]{8,128}$/.test(header) ? header : randomUUID();
|
|
}
|