docs: documents middleware matcher#40180
Merged
kodiakhq[bot] merged 3 commits intovercel:canaryfrom Sep 5, 2022
Merged
Conversation
d4b3643 to
47673e5
Compare
47673e5 to
ac301b8
Compare
timneutkens
approved these changes
Sep 5, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📖 What's in there?
Middleware matchers are powerful, but very few people realized it, because they are not really documented.
This PR tries to bring more clarity, and includes a more advanced example.
The example shows how to exclude several pages (no
/static, no/public), but also allow specific page in excluded paths (/public/disclaimer)🧪 How to test?
Run the example:
pnpm next dev examples/middleware-matcher, then browse to http://localhost:3000The first 3 links should not match, the last 3 ones should.
Don't forget to clear your localhost cookies if you change the middleware code.
🆙 Note to reviewers
Using session cookies to pass information from middleware to the rendered page is not great, because
document.cookieis not available during SSR, and because cookies persist when refreshing the page (making it hard to try different matchers)However, I couldn't find a simpler way to convey the information from the middleware to the page, and I meant to have something visual. The other option is to use response headers and curl commands, but...