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

Function loadConfig

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

Source from the content-addressed store, hash-verified

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

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