core/apps/webapp/app/services/httpAsyncStorage.server.ts
Harshith Mullapudi 060668e8c0 Fix: echo v2
2025-05-27 23:12:05 +05:30

21 lines
559 B
TypeScript

import { AsyncLocalStorage } from "node:async_hooks";
export type HttpLocalStorage = {
requestId: string;
path: string;
host: string;
method: string;
};
const httpLocalStorage = new AsyncLocalStorage<HttpLocalStorage>();
export type RunWithHttpContextFunction = <T>(context: HttpLocalStorage, fn: () => T) => T;
export function runWithHttpContext<T>(context: HttpLocalStorage, fn: () => T): T {
return httpLocalStorage.run(context, fn);
}
export function getHttpContext(): HttpLocalStorage | undefined {
return httpLocalStorage.getStore();
}