Skip to content

Commit 715d6a0

Browse files
committed
Fix Cloudflare Worker: enable nodejs_compat_populate_process_env
The Cloudflare Workers runtime does not define `process` by default, even with nodejs_compat enabled. Add the nodejs_compat_populate_process_env compatibility flag so that process.env is populated from Worker bindings (including .dev.vars in local development). This allows the identity key env var to be read at module scope without restructuring the example.
1 parent 1928031 commit 715d6a0

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

packages/examples/cloudflare/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ const greeter = restate.service({
2424
},
2525
});
2626

27-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
2827
const identityKeys =
29-
process.env?.RESTATE_IDENTITY_KEYS?.split(",").filter(Boolean);
28+
process.env.RESTATE_IDENTITY_KEYS?.split(",").filter(Boolean);
3029

3130
export default {
3231
fetch: restate.createEndpointHandler({ services: [greeter], identityKeys }),

packages/examples/cloudflare/wrangler.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ minify = false
1616

1717
# Enable NodeJS compatibility (used by the SDK for the Node Buffer API)
1818
compatibility_date = "2024-05-13"
19-
compatibility_flags = [ "nodejs_compat" ]
19+
compatibility_flags = [ "nodejs_compat", "nodejs_compat_populate_process_env" ]
2020

2121
[dev]
2222
ip = "0.0.0.0"

0 commit comments

Comments
 (0)