mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-10-09 03:20:56 +00:00
Replace the server-level `--demo` flag with per-request demo dispatch. The Rust API builds both a demo and real router; incoming requests with the `X-Arc-Demo: 1` header hit the demo router (auth disabled, static data), all others hit the real router with normal auth. The React web app gets a beaker icon toggle in the top nav bar (next to the theme toggle) that sets an `arc-demo` cookie. Loaders read the cookie to decide whether to send the `X-Arc-Demo: 1` header to the API. The `ARC_DEMO=1` env var still works as a default when no cookie is set. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
15 lines
641 B
TypeScript
15 lines
641 B
TypeScript
const COOKIE_NAME = "arc-demo";
|
|
|
|
/** Check whether demo mode is active for this request (cookie, then env var fallback). */
|
|
export function isDemoMode(request: Request): boolean {
|
|
const cookies = request.headers.get("Cookie") ?? "";
|
|
const match = cookies.match(/(?:^|;\s*)arc-demo=([^;]*)/);
|
|
if (match) return match[1] === "1";
|
|
return process.env.ARC_DEMO === "1";
|
|
}
|
|
|
|
/** Build a Set-Cookie header value to persist the demo mode preference. */
|
|
export function demoCookieHeader(enabled: boolean): string {
|
|
const value = enabled ? "1" : "0";
|
|
return `${COOKIE_NAME}=${value}; Path=/; SameSite=Lax; Max-Age=${60 * 60 * 24 * 365}`;
|
|
}
|