Proxy Matcher Paths
Medium · Proxy
By default Proxy runs for every request. export const config = { matcher: [...] } limits it to certain paths. A matcher is a string or an array of strings, and a request runs the proxy if **any** entry matches. Entries use named parameters:
- /about matches exactly /about.
- :name matches exactly one segment: /blog/:slug matches /blog/hello but not /blog/hello/comments.
- :name* (last segment) matches **zero or more** segments: /dashboard/:path* matches /dashboard, /dashboard/a and /dashboard/a/b.
- :name+ (last segment) matches **one or more** segments: /api/:path+ matches /api/users but not /api.
Write matchesProxy(matcher, pathname) that returns true or false. Split on / and ignore empty parts, so a trailing slash does not matter. Static segments are case-sensitive.
This is simplified: real matchers are compiled with path-to-regexp, so they also accept regular expressions (like the common "/((?!api|_next/static|favicon.ico).*)") and objects with has / missing conditions.