| 52 | const HINT_COOKIE_ATTRIBUTES = "Path=/; Secure; SameSite=Lax"; |
| 53 | |
| 54 | const isDocumentRequest = (request: Request): boolean => { |
| 55 | if (request.method !== "GET" && request.method !== "HEAD") return false; |
| 56 | // Browsers label navigations explicitly; non-browser clients fall back to |
| 57 | // content negotiation. Anything that isn't asking for a page (vite module |
| 58 | // requests, JSON fetches, health probes) passes through ungated. |
| 59 | const dest = request.headers.get("sec-fetch-dest"); |
| 60 | if (dest !== null) return dest === "document"; |
| 61 | return request.headers.get("accept")?.includes("text/html") ?? false; |
| 62 | }; |
| 63 | |
| 64 | // Lazy for the same reason start.ts instantiates the app handler lazily: this |
| 65 | // module reaches workers-only imports (cloudflare:workers via ./workos), which |