Skip to content

Commit f30e178

Browse files
fix: added support for "missing" matcher (#1905)
* fix: added support for missing matcher * fix: prettier fix * fix: removed skip from missing matcher tests * fix: updatiing demo to showcase missing matcher * fix: added new cookie testing page for missing matcher --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 2e5a728 commit f30e178

File tree

8 files changed

+337
-8
lines changed

8 files changed

+337
-8
lines changed

demos/middleware/middleware.ts

+22
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,25 @@ export async function middleware(req: NextRequest) {
5959
return response
6060
}
6161

62+
if(pathname.startsWith('/matcher-cookie')) {
63+
response = NextResponse.next()
64+
response.cookies.set('missingCookie', 'true')
65+
return response
66+
}
67+
6268
if (pathname.startsWith('/conditional')) {
6369
response = NextResponse.next()
6470
response.headers.set('x-modified-edge', 'true')
6571
response.headers.set('x-is-deno', 'Deno' in globalThis ? 'true' : 'false')
6672
return response
6773
}
6874

75+
if (pathname.startsWith('/missing')) {
76+
response = NextResponse.next()
77+
response.headers.set('x-cookie-missing', 'true')
78+
return response
79+
}
80+
6981
if (pathname.startsWith('/shows')) {
7082
if (pathname.startsWith('/shows/222')) {
7183
response = NextResponse.next()
@@ -119,6 +131,7 @@ export const config = {
119131
'/headers',
120132
{ source: '/static' },
121133
{ source: '/cookies' },
134+
{ source: '/matcher-cookie'},
122135
{ source: '/shows/((?!99|88).*)' },
123136
{
124137
source: '/conditional',
@@ -130,5 +143,14 @@ export const config = {
130143
},
131144
],
132145
},
146+
{
147+
source: '/missing',
148+
missing: [
149+
{
150+
type: 'cookie',
151+
key: 'missingCookie',
152+
}
153+
],
154+
},
133155
],
134156
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const MatcherCookie = () => {
2+
return (
3+
<div>
4+
<p>The cookie "missingCookie" should be set to true</p>
5+
</div>
6+
)
7+
}
8+
9+
export default MatcherCookie

demos/middleware/pages/missing.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react'
2+
import Link from 'next/link'
3+
4+
const Missing = () => {
5+
return (
6+
<div>
7+
<p>Will Check if 'missingCookie' is missing and display headers</p>
8+
<p>To test go to <Link href="/matcher-cookie">cookies page</Link> and come back</p>
9+
</div>
10+
)
11+
}
12+
13+
export default Missing

package-lock.json

+273
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Run Next.js seamlessly on Netlify",
55
"scripts": {
66
"build:demo": "cd demos/default && npm run build",
7-
"cy:open": "cypress open --config-file cypress/config/canary.json",
7+
"cy:open": "cypress open --config-file cypress/config/all.json",
88
"dev:demo": "next dev demos/default",
99
"format": "run-s format:check-fix:*",
1010
"format:ci": "run-s format:check:*",

packages/runtime/src/helpers/edge.ts

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface MiddlewareMatcher {
3131
regexp: string
3232
locale?: false
3333
has?: RouteHas[]
34+
missing?: RouteHas[]
3435
}
3536

3637
// This is the format after [email protected]

0 commit comments

Comments
 (0)