Skip to content

Commit f3ec0ab

Browse files
authored
refactor: simplify cloudflare ALS (#385)
1 parent 522076b commit f3ec0ab

File tree

1 file changed

+6
-12
lines changed
  • packages/cloudflare/src/cli/templates

1 file changed

+6
-12
lines changed

packages/cloudflare/src/cli/templates/worker.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,12 @@ import { handler as serverHandler } from "./server-functions/default/handler.mjs
1010

1111
const cloudflareContextALS = new AsyncLocalStorage<CloudflareContext>();
1212

13-
// Note: this symbol needs to be kept in sync with the one defined in `src/api/get-cloudflare-context.ts`
14-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
15-
(globalThis as any)[Symbol.for("__cloudflare-context__")] = new Proxy(
16-
{},
17-
{
18-
ownKeys: () => Reflect.ownKeys(cloudflareContextALS.getStore()!),
19-
getOwnPropertyDescriptor: (_, ...args) =>
20-
Reflect.getOwnPropertyDescriptor(cloudflareContextALS.getStore()!, ...args),
21-
get: (_, property) => Reflect.get(cloudflareContextALS.getStore()!, property),
22-
set: (_, property, value) => Reflect.set(cloudflareContextALS.getStore()!, property, value),
23-
}
24-
);
13+
// Note: this symbol needs to be kept in sync with `src/api/get-cloudflare-context.ts`
14+
Object.defineProperty(globalThis, Symbol.for("__cloudflare-context__"), {
15+
get() {
16+
return cloudflareContextALS.getStore();
17+
},
18+
});
2519

2620
// Populate process.env on the first request
2721
let processEnvPopulated = false;

0 commit comments

Comments
 (0)