Move app to apps/web-react in pnpm workspace layout

This commit is contained in:
Kalle
2026-08-16 09:20:33 +03:00
parent 7e365ccfcf
commit bbc8ea57af
2913 changed files with 227 additions and 250 deletions

View File

@@ -0,0 +1,26 @@
import { AsyncLocalStorage } from "node:async_hooks";
// TODO: this is only needed for our current hacky toast setup, once a proper one in place this middleware can be deleted
interface RequestContext {
/** Normalized request URL, as provided to middleware in framework mode
* (single-fetch `.data` suffix and internal search params removed). */
url: URL;
}
const requestContextAsyncLocalStorage = new AsyncLocalStorage<RequestContext>();
/** Runs `fn` with the given request context available to server-side helpers
* (e.g. toast redirects) that don't otherwise receive the request. */
export function runWithRequestContext<T>(
context: RequestContext,
fn: () => T,
): T {
return requestContextAsyncLocalStorage.run(context, fn);
}
/** Normalized pathname of the current request, or `undefined` outside a request
* context. Used to build absolute redirects from helpers lacking the request. */
export function currentRequestPathname(): string | undefined {
return requestContextAsyncLocalStorage.getStore()?.url.pathname;
}