Skip to content

Commit

Permalink
feat: replicate nitro production behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 8, 2024
1 parent 9975161 commit 36ad28e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/runtime/plugin.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default <NitroAppPlugin>function (nitroApp) {
const request = new Request(getRequestURL(event)) as Request & {
cf: typeof proxy.cf;
};

request.cf = proxy.cf;

event.context.cloudflare = {
Expand All @@ -39,6 +38,15 @@ export default <NitroAppPlugin>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
Expand Down

0 comments on commit 36ad28e

Please sign in to comment.