diff --git a/src/runtime/plugin.dev.ts b/src/runtime/plugin.dev.ts index 9ef0467..eab76df 100644 --- a/src/runtime/plugin.dev.ts +++ b/src/runtime/plugin.dev.ts @@ -30,7 +30,6 @@ export default function (nitroApp) { const request = new Request(getRequestURL(event)) as Request & { cf: typeof proxy.cf; }; - request.cf = proxy.cf; event.context.cloudflare = { @@ -39,6 +38,15 @@ export default function (nitroApp) { env: proxy.env, context: proxy.ctx, }; + + // Replicate Nitro production behavior + // https://github.com/unjs/nitro/blob/main/src/runtime/entries/cloudflare-pages.ts#L55 + // https://github.com/unjs/nitro/blob/main/src/runtime/app.ts#L120 + (globalThis as any).__env__ = proxy.env; + (event.node.req as any).__unenv__ = { + ...(event.node.req as any).__unenv__, + waitUntil: event.context.waitUntil, + }; }); // https://github.com/pi0/nitro-cloudflare-dev/issues/5