(env: CloudflareEnv)
| 94 | }; |
| 95 | |
| 96 | export const loadConfig = (env: CloudflareEnv): CloudflareConfig => { |
| 97 | const secretKey = env.EXECUTOR_SECRET_KEY?.trim(); |
| 98 | if (!secretKey || secretKey.length < 16) { |
| 99 | // oxlint-disable-next-line executor/no-try-catch-or-throw, executor/no-error-constructor -- boundary: the Worker must not boot without the at-rest secret key |
| 100 | throw new Error( |
| 101 | "EXECUTOR_SECRET_KEY must be set (wrangler secret put EXECUTOR_SECRET_KEY) — it encrypts stored secrets at rest in D1", |
| 102 | ); |
| 103 | } |
| 104 | const enableDevAuth = env.ENABLE_DEV_AUTH === "true"; |
| 105 | const webBaseUrl = resolvePublicOrigin({ explicit: env.VITE_PUBLIC_SITE_URL, env: {} }); |
| 106 | if (!webBaseUrl && !enableDevAuth && !warnedNoCloudflareOrigin) { |
| 107 | warnedNoCloudflareOrigin = true; |
| 108 | console.warn( |
| 109 | missingPublicOriginWarning({ |
| 110 | varName: "VITE_PUBLIC_SITE_URL", |
| 111 | fallback: "the per-request origin", |
| 112 | }), |
| 113 | ); |
| 114 | } |
| 115 | return { |
| 116 | accessTeamDomain: env.ACCESS_TEAM_DOMAIN.replace(/^https?:\/\//, "").replace(/\/+$/, ""), |
| 117 | accessAud: env.ACCESS_AUD, |
| 118 | accessNameClaim: env.ACCESS_NAME_CLAIM ?? "name", |
| 119 | accessGroupsClaim: env.ACCESS_GROUPS_CLAIM ?? "groups", |
| 120 | adminEmails: splitLower(env.ADMIN_EMAILS), |
| 121 | organizationId: env.SELF_HOSTED_ORG_ID ?? "default", |
| 122 | organizationName: env.SELF_HOSTED_ORG_NAME ?? "Default", |
| 123 | organizationSlug: resolveOrgSlug(env.SELF_HOSTED_ORG_SLUG), |
| 124 | secretKey, |
| 125 | allowLocalNetwork: env.ALLOW_LOCAL_NETWORK === "true", |
| 126 | // Pinned origin via the shared resolver. A Worker receives no PaaS platform |
| 127 | // vars (env: {} — there is nothing to detect), so only the explicit |
| 128 | // VITE_PUBLIC_SITE_URL applies; when it's unset we leave webBaseUrl undefined |
| 129 | // and let the per-request origin drive it (request.url — Cloudflare-set, not |
| 130 | // spoofable via Host). Warn once on a real deployment so the operator pins it, |
| 131 | // mirroring self-host (gated on enableDevAuth = local `wrangler dev`). |
| 132 | webBaseUrl, |
| 133 | enableDevAuth, |
| 134 | }; |
| 135 | }; |
no test coverage detected