middleware matcher
Unanswered
Russian Blue posted this in #help-forum
Russian BlueOP
Hey..,how can I modify this middleware
matcher so that public folder paths are excluded? export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
*/
'/((?!api|_next/static|_next/image).*)',
],
}3 Replies
Russian BlueOP
My assets are in
public/static-assetsAdding it like this seems to work:
but I’m a little confused by this from the docs:
'/((?!api|_next/static|_next/image|static-assets).*)', but I’m a little confused by this from the docs:
Good to know: For backward compatibility, Next.js always considers /public as /public/index. Therefore, a matcher of /public/:path will match.
What does it mean?
if you need to match /public, you need to specify /public/:path* (with *, zero or more, or ['/public', '/public/:path'])
but actually, for backward compatibility, /public is considered as /public/index
so, you don't need *, just /public/:path is okay, because it matches /public/index