Skip to content

Commit

Permalink
Merge branch 'canary' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored Sep 13, 2022
2 parents 7146c38 + f33c23c commit eabe550
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions docs/advanced-features/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ export const config = {
}
```

The `matcher` config allows full regex so matching like negative lookaheads or character matching is supported. An example of a negative lookahead to match all except specific paths can be seen here:

```js
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).*)',
],
}
```

> **Note:** The `matcher` values need to be constants so they can be statically analyzed at build-time. Dynamic values such as variables will be ignored.
Configured matchers:
Expand All @@ -101,8 +117,6 @@ Read more details on [path-to-regexp](https://github.com/pillarjs/path-to-regexp

> **Note:** For backward compatibility, Next.js always considers `/public` as `/public/index`. Therefore, a matcher of `/public/:path` will match.
> **Note:** It is not possible to exclude middleware from matching static path starting with `_next/`. This allow enforcing security with middleware.
### Conditional Statements

```typescript
Expand Down

0 comments on commit eabe550

Please sign in to comment.