mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-01 15:48:23 -05:00
Move app to apps/web-react in pnpm workspace layout
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
|
||||
interface SessionIdContext {
|
||||
sessionId: string | undefined;
|
||||
}
|
||||
|
||||
export const sessionIdAsyncLocalStorage =
|
||||
new AsyncLocalStorage<SessionIdContext>();
|
||||
|
||||
function getSessionId(): string | undefined {
|
||||
return sessionIdAsyncLocalStorage.getStore()?.sessionId;
|
||||
}
|
||||
|
||||
declare global {
|
||||
var __getServerSessionId: (() => string | undefined) | undefined;
|
||||
}
|
||||
|
||||
globalThis.__getServerSessionId = getSessionId;
|
||||
@@ -0,0 +1,17 @@
|
||||
import { sessionIdAsyncLocalStorage } from "./session-id-context.server";
|
||||
|
||||
type MiddlewareArgs = {
|
||||
request: Request;
|
||||
context: unknown;
|
||||
};
|
||||
|
||||
type MiddlewareFn = (
|
||||
args: MiddlewareArgs,
|
||||
next: () => Promise<Response>,
|
||||
) => Promise<Response>;
|
||||
|
||||
export const sessionIdMiddleware: MiddlewareFn = async ({ request }, next) => {
|
||||
const sessionId = request.headers.get("Sendou-Session-Id") ?? undefined;
|
||||
|
||||
return sessionIdAsyncLocalStorage.run({ sessionId }, () => next());
|
||||
};
|
||||
Reference in New Issue
Block a user