Skip to content
Discussion options

You must be logged in to vote

Hi, you should be seeing an error with the above source ('/(?!^\/api\/$)') what version of Next.js are you on? Using the above source the following error is shown on the latest version of Next.js v9.5.3

Error parsing `/(?!^/api/$)` https://err.sh/vercel/next.js/invalid-route-source
Reason: Pattern cannot start with "?" at 2

  /(?!^/api/$)
    ^

`source` parse failed for route {"source":"/(?!^/api/$)","headers":[{"key":"x-hello","value":"world"}]}

Error: Invalid header found

To match against all routes except /api/* you would want the something like the below route.

module.exports = {
  headers() {
    return [
      {
        source: '/((?!api$|api/).*)',
        headers: [
          {

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@paambaati
Comment options

@StephaneBischoff
Comment options

Answer selected by paambaati
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants