I have a middleware on a Next.js project, and I want to negate my /api/* route.
In other words, I want middleware to run for every route except anything that starts with /api/. I couldn't find an example in the docs.
How do I achieve that (of course, without writing all included routes one by one)?
Looks like the middleware docs have been updated to account for something like this.
nextjs middleware docs
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - static (static files)
* - favicon.ico (favicon file)
*/
'/((?!api|static|favicon.ico).*)',
],
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With