nitro
nitro copied to clipboard
Middleware registered in plugins is never executed
Environment
nitropack v0.5.4, no extra config
Reproduction
Given the following plugin:
// plugins/test.ts
export default defineNitroPlugin(nitroApp => {
nitroApp.h3App.use('/', () => console.log('Middleware ran'))
console.log('Plugin registered')
})
The plugin appears to register correctly ('Plugin registered' is printed), but the middleware added with h3App.use is never executed ('Middleware ran' is never printed when navigating to any route).
Describe the bug
Any middleware added inside a nitro plugin with nitroApp.h3App.use
or other related methods is never executed.
This might be an intentional / known limitation of how plugins work, but it feels unexpected, given that the method throws no error and is readily accessible.
Additional context
No response
Logs
No response
See https://github.com/unjs/nitro/pull/302 and https://github.com/nuxt/framework/issues/5527#issuecomment-1160789814.
Those issues appear to be about adding new routes, not middleware. Unless there is some way to add middleware directly to the router that I'm unaware of, I don't really get why this issue was closed.