Skip to content

Commit acc8d01

Browse files
committed
refactor cloudflare part
1 parent d3e4b48 commit acc8d01

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/open-next/src/overrides/wrappers/cloudflare-node.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const handler: WrapperHandler<InternalEvent, InternalResult> =
1616
request: Request,
1717
env: Record<string, string>,
1818
ctx: any,
19+
abortSignal: AbortSignal,
1920
): Promise<Response> => {
2021
globalThis.process = process;
21-
2222
// Set the environment variables
2323
// Cloudflare suggests to not override the process.env object but instead apply the values to it
2424
for (const [key, value] of Object.entries(env)) {
@@ -66,9 +66,10 @@ const handler: WrapperHandler<InternalEvent, InternalResult> =
6666

6767
return Writable.fromWeb(writable);
6868
},
69-
// For some reason the signal from `request` here did not work.
70-
// @ts-expect-error This is defined in init from cloudflare
71-
abortSignal: globalThis[Symbol.for("__cloudflare-context__")].signal,
69+
// This is for passing along the original abort signal from the initial Request you retrieve in your worker
70+
// Ensures that the response we pass to NextServer is aborted if the request is aborted
71+
// By doing this `request.signal.onabort` will work in route handlers
72+
abortSignal: abortSignal,
7273
};
7374

7475
ctx.waitUntil(

0 commit comments

Comments
 (0)