File tree Expand file tree Collapse file tree 8 files changed +413
-19
lines changed
cypress/integration/middleware
packages/runtime/src/templates/edge-shared Expand file tree Collapse file tree 8 files changed +413
-19
lines changed Original file line number Diff line number Diff line change 1+ name : Deno tests
2+
3+ on :
4+ push :
5+ branches : [main]
6+ pull_request :
7+ branches : [main]
8+
9+ jobs :
10+ test :
11+ runs-on : ubuntu-latest
12+
13+ steps :
14+ - name : Git Checkout Deno Module
15+ uses : actions/checkout@v2
16+ - name : Use Deno Version ${{ matrix.deno-version }}
17+ uses : denolib/setup-deno@v2
18+ with :
19+ deno-version : vx.x.x
20+ - name : Test Deno
21+ run : deno test packages/runtime/src/templates/edge-shared/
Original file line number Diff line number Diff line change 11describe ( 'Enhanced middleware' , ( ) => {
2- it ( 'adds request headers' , ( ) => {
3- cy . request ( '/api/hello' ) . then ( ( response ) => {
4- expect ( response . body ) . to . have . nested . property ( 'headers.x-hello' , 'world' )
5- } )
6- } )
7-
8- it ( 'adds request headers to a rewrite' , ( ) => {
9- cy . request ( '/headers' ) . then ( ( response ) => {
10- expect ( response . body ) . to . have . nested . property ( 'headers.x-hello' , 'world' )
11- } )
12- } )
13-
142 it ( 'rewrites the response body' , ( ) => {
153 cy . visit ( '/static' )
164 cy . get ( '#message' ) . contains ( 'This was static but has been transformed in' )
Original file line number Diff line number Diff line change 11describe ( 'Standard middleware' , ( ) => {
2+ it ( 'adds request headers' , ( ) => {
3+ cy . request ( '/api/hello' ) . then ( ( response ) => {
4+ expect ( response . body ) . to . have . nested . property ( 'headers.x-hello' , 'world' )
5+ } )
6+ } )
7+
8+ it ( 'adds request headers to a rewrite' , ( ) => {
9+ cy . request ( '/headers' ) . then ( ( response ) => {
10+ expect ( response . body ) . to . have . nested . property ( 'headers.x-hello' , 'world' )
11+ } )
12+ } )
13+
214 it ( 'rewrites to internal page' , ( ) => {
315 // preview mode is off by default
416 cy . visit ( '/shows/rewriteme' )
Original file line number Diff line number Diff line change @@ -8,6 +8,18 @@ export async function middleware(req: NextRequest) {
88 let response
99 const { pathname } = req . nextUrl
1010
11+ if ( pathname . startsWith ( '/api/hello' ) ) {
12+ // Next 13 request header mutation functionality
13+ const headers = new Headers ( req . headers )
14+
15+ headers . set ( 'x-hello' , 'world' )
16+ return NextResponse . next ( {
17+ request : {
18+ headers
19+ }
20+ } )
21+ }
22+
1123 const request = new MiddlewareRequest ( req )
1224 if ( pathname . startsWith ( '/static' ) ) {
1325 // Unlike NextResponse.next(), this actually sends the request to the origin
@@ -24,12 +36,6 @@ export async function middleware(req: NextRequest) {
2436 return res
2537 }
2638
27- if ( pathname . startsWith ( '/api/hello' ) ) {
28- // Add a header to the request
29- req . headers . set ( 'x-hello' , 'world' )
30- return request . next ( )
31- }
32-
3339 if ( pathname . startsWith ( '/api/geo' ) ) {
3440 req . headers . set ( 'x-geo-country' , req . geo . country )
3541 req . headers . set ( 'x-geo-region' , req . geo . region )
Original file line number Diff line number Diff line change 1818 "postinstall" : " run-s build install-husky" ,
1919 "install-husky" : " if-env CI=1 || husky install node_modules/@netlify/eslint-config-node/.husky" ,
2020 "test" : " run-s build:demo test:jest" ,
21+ "test:deno" : " deno test packages/runtime/src/templates/edge-shared/" ,
2122 "test:next" : " jest -c test/e2e/jest.config.js" ,
2223 "test:next:disabled" : " RUN_SKIPPED_TESTS=1 jest -c test/e2e/jest.config.disabled.js" ,
2324 "test:next:all" : " RUN_SKIPPED_TESTS=1 jest -c test/e2e/jest.config.all.js" ,
101102 " **/test/**/*.spec.ts" ,
102103 " !**/test/e2e/**" ,
103104 " !**/test/fixtures/**" ,
104- " !**/test/sample/**"
105+ " !**/test/sample/**" ,
106+ " !**/test/templates/edge-shared/**"
105107 ],
106108 "transform" : {
107109 "\\ .[jt]sx?$" : " babel-jest"
You can’t perform that action at this time.
0 commit comments