mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-01 07:37:55 -05:00
17 lines
585 B
TypeScript
17 lines
585 B
TypeScript
import type { MiddlewareFunction } from "react-router";
|
|
import { viewerTimezoneAsyncLocalStorage } from "./timezone-context.server";
|
|
import { viewerTimezoneFromCookieHeader } from "./timezone-cookie";
|
|
|
|
/**
|
|
* Resolves the viewer's timezone from their cookie and makes it available to
|
|
* loaders via `getViewerTimezone` for the duration of the request.
|
|
*/
|
|
export const timezoneMiddleware: MiddlewareFunction<Response> = (
|
|
{ request },
|
|
next,
|
|
) =>
|
|
viewerTimezoneAsyncLocalStorage.run(
|
|
{ timezone: viewerTimezoneFromCookieHeader(request.headers.get("Cookie")) },
|
|
() => next(),
|
|
);
|