Skip to content

fix: added support for "missing" matcher #1905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions demos/middleware/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,25 @@ export async function middleware(req: NextRequest) {
return response
}

if(pathname.startsWith('/matcher-cookie')) {
response = NextResponse.next()
response.cookies.set('missingCookie', 'true')
return response
}

if (pathname.startsWith('/conditional')) {
response = NextResponse.next()
response.headers.set('x-modified-edge', 'true')
response.headers.set('x-is-deno', 'Deno' in globalThis ? 'true' : 'false')
return response
}

if (pathname.startsWith('/missing')) {
response = NextResponse.next()
response.headers.set('x-cookie-missing', 'true')
return response
}

if (pathname.startsWith('/shows')) {
if (pathname.startsWith('/shows/222')) {
response = NextResponse.next()
Expand Down Expand Up @@ -119,6 +131,7 @@ export const config = {
'/headers',
{ source: '/static' },
{ source: '/cookies' },
{ source: '/matcher-cookie'},
{ source: '/shows/((?!99|88).*)' },
{
source: '/conditional',
Expand All @@ -130,5 +143,14 @@ export const config = {
},
],
},
{
source: '/missing',
missing: [
{
type: 'cookie',
key: 'missingCookie',
}
],
},
],
}
9 changes: 9 additions & 0 deletions demos/middleware/pages/matcher-cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const MatcherCookie = () => {
return (
<div>
<p>The cookie "missingCookie" should be set to true</p>
</div>
)
}

export default MatcherCookie
13 changes: 13 additions & 0 deletions demos/middleware/pages/missing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react'
import Link from 'next/link'

const Missing = () => {
return (
<div>
<p>Will Check if 'missingCookie' is missing and display headers</p>
<p>To test go to <Link href="/matcher-cookie">cookies page</Link> and come back</p>
</div>
)
}

export default Missing
273 changes: 273 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Run Next.js seamlessly on Netlify",
"scripts": {
"build:demo": "cd demos/default && npm run build",
"cy:open": "cypress open --config-file cypress/config/canary.json",
"cy:open": "cypress open --config-file cypress/config/all.json",
"dev:demo": "next dev demos/default",
"format": "run-s format:check-fix:*",
"format:ci": "run-s format:check:*",
Expand Down
1 change: 1 addition & 0 deletions packages/runtime/src/helpers/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface MiddlewareMatcher {
regexp: string
locale?: false
has?: RouteHas[]
missing?: RouteHas[]
}

// This is the format after next@12.3.0
Expand Down
Loading