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

Function loadConfig

apps/host-cloudflare/src/config.ts:96–135  ·  view source on GitHub ↗
(env: CloudflareEnv)

Source from the content-addressed store, hash-verified

94};
95
96export 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};

Callers 2

makeCloudflareAppFunction · 0.90
constructorMethod · 0.90

Calls 6

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

Tested by

no test coverage detected