Skip to content

Commit 36ad28e

Browse files
committed
feat: replicate nitro production behavior
1 parent 9975161 commit 36ad28e

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/runtime/plugin.dev.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export default <NitroAppPlugin>function (nitroApp) {
3030
const request = new Request(getRequestURL(event)) as Request & {
3131
cf: typeof proxy.cf;
3232
};
33-
3433
request.cf = proxy.cf;
3534

3635
event.context.cloudflare = {
@@ -39,6 +38,15 @@ export default <NitroAppPlugin>function (nitroApp) {
3938
env: proxy.env,
4039
context: proxy.ctx,
4140
};
41+
42+
// Replicate Nitro production behavior
43+
// https://github.com/unjs/nitro/blob/main/src/runtime/entries/cloudflare-pages.ts#L55
44+
// https://github.com/unjs/nitro/blob/main/src/runtime/app.ts#L120
45+
(globalThis as any).__env__ = proxy.env;
46+
(event.node.req as any).__unenv__ = {
47+
...(event.node.req as any).__unenv__,
48+
waitUntil: event.context.waitUntil,
49+
};
4250
});
4351

4452
// https://github.com/pi0/nitro-cloudflare-dev/issues/5

0 commit comments

Comments
 (0)