Skip to content

Commit

Permalink
fix: allow access to the context within request hook
Browse files Browse the repository at this point in the history
resolves #5
  • Loading branch information
pi0 committed Mar 8, 2024
1 parent f33599e commit cab495a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/nitro/plugins/test.ts
@@ -0,0 +1,8 @@
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook("request", (event) => {
console.log(
"event.context.cloudflare in request hook",
!!event.context.cloudflare,
);
});
});
5 changes: 5 additions & 0 deletions src/runtime/plugin.dev.ts
Expand Up @@ -35,6 +35,11 @@ export default <NitroAppPlugin>function (nitroApp) {
};
});

// https://github.com/pi0/nitro-cloudflare-dev/issues/5
// https://github.com/unjs/hookable/issues/98
// @ts-expect-error
nitroApp.hooks._hooks.request.unshift(nitroApp.hooks._hooks.request.pop());

// Dispose proxy when Nitro is closed
nitroApp.hooks.hook("close", () => {
return _proxy?.then((proxy) => proxy.dispose);
Expand Down

0 comments on commit cab495a

Please sign in to comment.