History

Fix cloud app 500s by lazily accessing Cloudflare env bindings

Eagerly reading cfEnv.HYPERDRIVE/LOADER/MARKETING at module load time causes every request to fail with HTTPError 500. Use property getters so bindings are only accessed within a request context.

Rhys Sullivan committed 7 months ago

Commit c8e00a51 parent 473731b1 file · +4 −4Browse files

Unified · Split

apps/cloud/src/env.ts+4−4
@@ -58,7 +58,7 @@ export const server = createEnv(serverShape, { · 57 unmodified lines
58// ---------------------------------------------------------------------------58// ---------------------------------------------------------------------------
59 59
60export const cf = {60export const cf = {
61 hyperdrive: cfEnv.HYPERDRIVE,61 get hyperdrive() { return cfEnv.HYPERDRIVE; },
62 loader: cfEnv.LOADER,62 get loader() { return cfEnv.LOADER; },
63 marketing: cfEnv.MARKETING,63 get marketing() { return cfEnv.MARKETING; },
64} as const;64};