-
Notifications
You must be signed in to change notification settings - Fork 554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
middleware for special routes #239
Comments
Did you find a solution for this issue? |
@mhfeizi I think currently not, middlewares are called on every route. |
We encountered the same issue, and created a helper function to use instead of DefineEventHandler, to more easily handle middleware per route.
But perhaps there are better ways to do this? @danielroe what do you think? |
There's a h3 feature coming that will enable this unjs/h3#424 |
Currently, you can conditionally run middleware in some routes: // middleware/api-auth.ts
export default eventHandler(event => {
if (event.path.startsWith('/api')) {
await checkAPIAuth(event)
return
}
}) with the upcoming unjs/h3#485, you can also directly define hooks only on routes you want alternatively in route level: // api/foo.ts
export default eventHandler({
before: [checkAPIAuth],
handler(event) {
//
}
}) @clopezpro please use |
magnificent, thank you very much |
Is it possible to add middleware for special routes?
The text was updated successfully, but these errors were encountered: