nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Allow arbitrary route meta

Open naveeng2402 opened this issue 6 months ago • 1 comments

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?

naveeng2402 avatar Jun 10 '25 02:06 naveeng2402

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.

ssahillppatell avatar Jun 17 '25 20:06 ssahillppatell

https://github.com/h3js/h3/pull/1118

I opened this issue requesting something similar to this

naveeng2402 avatar Jul 07 '25 08:07 naveeng2402