mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-25 04:37:13 -05:00
14 lines
510 B
TypeScript
14 lines
510 B
TypeScript
import type { MiddlewareFunction } from "react-router";
|
|
import { viewerTimezoneAsyncLocalStorage } from "./timezone-context.server";
|
|
import { viewerTimezoneFromCookieHeader } from "./timezone-cookie";
|
|
|
|
/** Reads the timezone cookie into request context for `getViewerTimezone`. */
|
|
export const timezoneMiddleware: MiddlewareFunction<Response> = (
|
|
{ request },
|
|
next,
|
|
) =>
|
|
viewerTimezoneAsyncLocalStorage.run(
|
|
{ timezone: viewerTimezoneFromCookieHeader(request.headers.get("Cookie")) },
|
|
() => next(),
|
|
);
|