File tree 16 files changed +514
-80
lines changed
16 files changed +514
-80
lines changed Original file line number Diff line number Diff line change 4
4
" demos/middleware/.netlify/edge-functions" ,
5
5
" demos/server-components/.netlify/edge-functions" ,
6
6
],
7
- "deno.unstable" : true ,
8
- "deno.importMap" : " demos/server-components/.netlify/edge-functions-import-map.json"
7
+ "deno.unstable" : true
9
8
}
Original file line number Diff line number Diff line change @@ -5,16 +5,13 @@ import { MiddlewareRequest } from '@netlify/next'
5
5
6
6
export async function middleware ( req : NextRequest ) {
7
7
let response
8
- const {
9
- nextUrl : { pathname } ,
10
- } = req
8
+ const { pathname } = req . nextUrl
11
9
12
10
const request = new MiddlewareRequest ( req )
13
-
14
11
if ( pathname . startsWith ( '/static' ) ) {
15
12
// Unlike NextResponse.next(), this actually sends the request to the origin
16
13
const res = await request . next ( )
17
- const message = `This was static but has been transformed in ${ req . geo . city } `
14
+ const message = `This was static but has been transformed in ${ req . geo ? .city } `
18
15
19
16
// Transform the response HTML and props
20
17
res . replaceText ( 'p[id=message]' , message )
@@ -58,6 +55,16 @@ export async function middleware(req: NextRequest) {
58
55
response . headers . set ( 'x-modified-in-rewrite' , 'true' )
59
56
}
60
57
58
+ if ( pathname . startsWith ( '/shows/redirectme' ) ) {
59
+ const url = req . nextUrl . clone ( )
60
+ url . pathname = '/shows/100'
61
+ response = NextResponse . redirect ( url )
62
+ }
63
+
64
+ if ( pathname . startsWith ( '/shows/redirectexternal' ) ) {
65
+ response = NextResponse . redirect ( 'http://example.com/' )
66
+ }
67
+
61
68
if ( ! response ) {
62
69
response = NextResponse . next ( )
63
70
}
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ publish = ".next"
4
4
ignore = " if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ../..; fi;"
5
5
6
6
[[plugins ]]
7
+ # Switch these when testing `ntl dev`
8
+ # package = "@netlify/plugin-nextjs"
7
9
package = " ../plugin-wrapper/"
8
10
9
11
# This is a fake plugin, that makes it run npm install
@@ -15,16 +17,14 @@ included_files = [
15
17
" !node_modules/sharp/vendor/8.12.2/darwin-*/**/*" ,
16
18
" !node_modules/sharp/build/Release/sharp-darwin-*"
17
19
]
18
-
19
- [dev ]
20
- framework = " #static"
21
-
22
- [[redirects ]]
23
- from = " /_next/static/*"
24
- to = " /static/:splat"
25
- status = 200
26
-
27
- [[redirects ]]
28
- from = " /*"
29
- to = " /.netlify/functions/___netlify-handler"
30
- status = 200
20
+ # Uncomment this if testing the built files rather than dev
21
+ # [dev]
22
+ # framework = "#static"
23
+ # [[redirects]]
24
+ # from = "/_next/static/*"
25
+ # to = "/static/:splat"
26
+ # status = 200
27
+ # [[redirects]]
28
+ # from = "/*"
29
+ # to = "/.netlify/functions/___netlify-handler"
30
+ # status = 200
Original file line number Diff line number Diff line change 9
9
"ntl" : " ntl-internal"
10
10
},
11
11
"dependencies" : {
12
- "@netlify/plugin-nextjs" : " *" ,
13
12
"@netlify/next" : " *" ,
13
+ "@netlify/plugin-nextjs" : " *" ,
14
14
"next" : " ^12.2.0" ,
15
15
"react" : " 18.0.0" ,
16
16
"react-dom" : " 18.0.0"
24
24
"npm-run-all" : " ^4.1.5" ,
25
25
"typescript" : " ^4.6.3"
26
26
}
27
- }
27
+ }
Original file line number Diff line number Diff line change @@ -25,6 +25,12 @@ export default function Home() {
25
25
< p >
26
26
< Link href = "/shows/rewrite-external" > Rewrite to external URL</ Link >
27
27
</ p >
28
+ < p >
29
+ < Link href = "/shows/redirectme" > Redirect URL</ Link >
30
+ </ p >
31
+ < p >
32
+ < Link href = "/shows/redirectexternal" > Redirect to external URL</ Link >
33
+ </ p >
28
34
< p >
29
35
< Link href = "/shows/static/3" > Add header to static page</ Link >
30
36
</ p >
You can’t perform that action at this time.
0 commit comments