MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / loadConfig

Function loadConfig

apps/host-cloudflare/src/config.ts:132–178  ·  view source on GitHub ↗
(env: CloudflareConfigEnv)

Source from the content-addressed store, hash-verified

130};
131
132export const loadConfig = (env: CloudflareConfigEnv): CloudflareConfig => {
133 const secretKey = env.EXECUTOR_SECRET_KEY?.trim();
134 if (!secretKey || secretKey.length < 16) {
135 // 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
136 throw new Error(
137 "EXECUTOR_SECRET_KEY must be set (wrangler secret put EXECUTOR_SECRET_KEY) — it encrypts stored secrets at rest in D1",
138 );
139 }
140 const enableDevAuth = env.ENABLE_DEV_AUTH === "true";
141 const accessTeamDomain = normalizeAccessTeamDomain(env.ACCESS_TEAM_DOMAIN);
142 const accessAud = (env.ACCESS_AUD ?? "").trim();
143 const missingAccessVars = missingCloudflareAccessVars(env);
144 if (missingAccessVars.length > 0) {
145 // oxlint-disable-next-line executor/no-try-catch-or-throw, executor/no-error-constructor -- boundary: production must fail closed without a valid Access verifier
146 throw new Error(cloudflareAccessConfigErrorMessage(missingAccessVars));
147 }
148 const webBaseUrl = resolvePublicOrigin({ explicit: env.VITE_PUBLIC_SITE_URL, env: {} });
149 if (!webBaseUrl && !enableDevAuth && !warnedNoCloudflareOrigin) {
150 warnedNoCloudflareOrigin = true;
151 console.warn(
152 missingPublicOriginWarning({
153 varName: "VITE_PUBLIC_SITE_URL",
154 fallback: "the per-request origin",
155 }),
156 );
157 }
158 return {
159 accessTeamDomain,
160 accessAud,
161 accessNameClaim: env.ACCESS_NAME_CLAIM ?? "name",
162 accessGroupsClaim: env.ACCESS_GROUPS_CLAIM ?? "groups",
163 adminEmails: splitLower(env.ADMIN_EMAILS),
164 organizationId: env.SELF_HOSTED_ORG_ID ?? "default",
165 organizationName: env.SELF_HOSTED_ORG_NAME ?? "Default",
166 organizationSlug: resolveOrgSlug(env.SELF_HOSTED_ORG_SLUG),
167 secretKey,
168 allowLocalNetwork: env.ALLOW_LOCAL_NETWORK === "true",
169 // Pinned origin via the shared resolver. A Worker receives no PaaS platform
170 // vars (env: {} — there is nothing to detect), so only the explicit
171 // VITE_PUBLIC_SITE_URL applies; when it's unset we leave webBaseUrl undefined
172 // and let the per-request origin drive it (request.url — Cloudflare-set, not
173 // spoofable via Host). Warn once on a real deployment so the operator pins it,
174 // mirroring self-host (gated on enableDevAuth = local `wrangler dev`).
175 webBaseUrl,
176 enableDevAuth,
177 };
178};

Callers 3

config.test.tsFile · 0.90
makeCloudflareAppFunction · 0.90
constructorMethod · 0.90

Calls 8

resolvePublicOriginFunction · 0.90
splitLowerFunction · 0.85
warnMethod · 0.80
resolveOrgSlugFunction · 0.70

Tested by

no test coverage detected