N
Nuxt3mo ago
Titan

SOLVED: How to create server middleware just for API routes?

I'm trying to create middleware for my server API routes, but I've found they also run on SSR mode when trying to render the client, which has nothing to do with my API. How do I target just API H3 routes with middleware?
2 Replies
manniL
manniL3mo ago
check if the path starts with /api in the middleware
Titan
Titan3mo ago
thanks I'll do that, just checking there wasn't an API or function built in to do that.
export default defineEventHandler(async event => {
if (event.path.startsWith('/api')) {
export default defineEventHandler(async event => {
if (event.path.startsWith('/api')) {