NuxtN
Nuxt2y ago
Phillip

appMiddleware for API routes?

When an API under /api/admin is being called I want to run my middleware under /server/middleware/admin.ts
I thought I could add a route rule to the nuxt.config.ts like this:
routeRules: {
    '/api/admin/**': { appMiddleware: 'admin' }
},


But still, the middleware runs on every request which is also mentioned in the docs (https://nuxt.com/docs/guide/directory-structure/server#server-middleware)

But I was wondering if something like this '/api/admin/**': { appMiddleware: 'admin' } is possible?

Otherwise I would need to do something like if (requestUrl.includes('/api/admin')) right?
Nuxt
The server/ directory is used to register API and server handlers to your application.
Was this page helpful?