Skip to content

Commit 2754445

Browse files
fixup! enable getCloudflareContext to work in middlewares via a new enableEdgeDevGetCloudflareContext utility
clarify args of `runInContext`
1 parent 7fda6ca commit 2754445

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/cloudflare/src/api/cloudflare-context.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Context, RunningCodeOptions } from "node:vm";
2+
13
declare global {
24
interface CloudflareEnv {
35
NEXT_CACHE_WORKERS_KV?: KVNamespace;
@@ -121,10 +123,14 @@ export async function enableEdgeDevGetCloudflareContext() {
121123

122124
const context = await getCloudflareContextFromWrangler();
123125

124-
vmModule.runInContext = (...args: [string, RuntimeContext, ...unknown[]]) => {
125-
const runtimeContext = args[1];
126+
vmModule.runInContext = (
127+
code: string,
128+
contextifiedObject: Context,
129+
options?: RunningCodeOptions | string
130+
) => {
131+
const runtimeContext = contextifiedObject as RuntimeContext;
126132
runtimeContext[cloudflareContextInNextDevSymbol] ??= context;
127-
return originalRunInContext(...args);
133+
return originalRunInContext(code, contextifiedObject, options);
128134
};
129135
}
130136

0 commit comments

Comments
 (0)