Skip to content

Commit 49a399c

Browse files
committed
chore: add demo
1 parent bcb90bf commit 49a399c

File tree

3 files changed

+65
-37
lines changed

3 files changed

+65
-37
lines changed

demos/middleware/middleware.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { NextResponse } from 'next/server'
22
import { MiddlewareRequest, NextRequest } from '@netlify/next'
33

4+
// Next.js replaces this with a stub polyfill. This import is just to test that stub.
5+
import pointlessFetch from 'isomorphic-unfetch'
6+
47
export async function middleware(req: NextRequest) {
58
let response
69
const { pathname } = req.nextUrl
@@ -58,6 +61,12 @@ export async function middleware(req: NextRequest) {
5861
}
5962

6063
if (pathname.startsWith('/shows')) {
64+
if (pathname.startsWith('/shows/222')) {
65+
response = NextResponse.next()
66+
const res = await pointlessFetch('http://www.example.com/')
67+
response.headers.set('x-example-server', res.headers.get('server'))
68+
}
69+
6170
if (pathname.startsWith('/shows/rewrite-absolute')) {
6271
response = NextResponse.rewrite(new URL('/shows/100', req.url))
6372
response.headers.set('x-modified-in-rewrite', 'true')

demos/middleware/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dependencies": {
1212
"@netlify/next": "*",
1313
"@netlify/plugin-nextjs": "*",
14+
"isomorphic-unfetch": "^3.1.0",
1415
"next": "^13.0.3",
1516
"react": "^18.2.0",
1617
"react-dom": "^18.2.0"
@@ -24,4 +25,4 @@
2425
"npm-run-all": "^4.1.5",
2526
"typescript": "^4.6.3"
2627
}
27-
}
28+
}

package-lock.json

Lines changed: 54 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)