nitro
nitro copied to clipboard
Allow arbitrary route meta
Describe the feature
Expose the route meta in event, so we can do something like mentioned below similar to nuxt middlewares
// server/api/index.ts
defineRouteMeta({
public: true,
});
export default defineEventHandler((event) => {
return "Start by editing <code>server/routes/index.ts</code>.";
});
// middleware/auth.ts
export default defineEventHandler((event) => {
const meta = getRouteMeta(event)
if (meta.public) return
// auth logic
});
Additional information
- [x] Would you be willing to help implement this feature?
defineRouteMeta is not intended for this use case. It's for specifying OpenAPI meta.
Also, middleware is called before the actual request, so there is no way to get the route metadata in the middleware.
We can have an arbitrary meta object in route rules. But that would probably be a deviation from web standards.
https://github.com/h3js/h3/pull/1118
I opened this issue requesting something similar to this