File tree 8 files changed +413
-19
lines changed
cypress/integration/middleware
packages/runtime/src/templates/edge-shared
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 1
1
describe ( '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
-
14
2
it ( 'rewrites the response body' , ( ) => {
15
3
cy . visit ( '/static' )
16
4
cy . get ( '#message' ) . contains ( 'This was static but has been transformed in' )
Original file line number Diff line number Diff line change 1
1
describe ( '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
+
2
14
it ( 'rewrites to internal page' , ( ) => {
3
15
// preview mode is off by default
4
16
cy . visit ( '/shows/rewriteme' )
Original file line number Diff line number Diff line change @@ -8,6 +8,18 @@ export async function middleware(req: NextRequest) {
8
8
let response
9
9
const { pathname } = req . nextUrl
10
10
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
+
11
23
const request = new MiddlewareRequest ( req )
12
24
if ( pathname . startsWith ( '/static' ) ) {
13
25
// Unlike NextResponse.next(), this actually sends the request to the origin
@@ -24,12 +36,6 @@ export async function middleware(req: NextRequest) {
24
36
return res
25
37
}
26
38
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
-
33
39
if ( pathname . startsWith ( '/api/geo' ) ) {
34
40
req . headers . set ( 'x-geo-country' , req . geo . country )
35
41
req . headers . set ( 'x-geo-region' , req . geo . region )
Original file line number Diff line number Diff line change 18
18
"postinstall" : " run-s build install-husky" ,
19
19
"install-husky" : " if-env CI=1 || husky install node_modules/@netlify/eslint-config-node/.husky" ,
20
20
"test" : " run-s build:demo test:jest" ,
21
+ "test:deno" : " deno test packages/runtime/src/templates/edge-shared/" ,
21
22
"test:next" : " jest -c test/e2e/jest.config.js" ,
22
23
"test:next:disabled" : " RUN_SKIPPED_TESTS=1 jest -c test/e2e/jest.config.disabled.js" ,
23
24
"test:next:all" : " RUN_SKIPPED_TESTS=1 jest -c test/e2e/jest.config.all.js" ,
101
102
" **/test/**/*.spec.ts" ,
102
103
" !**/test/e2e/**" ,
103
104
" !**/test/fixtures/**" ,
104
- " !**/test/sample/**"
105
+ " !**/test/sample/**" ,
106
+ " !**/test/templates/edge-shared/**"
105
107
],
106
108
"transform" : {
107
109
"\\ .[jt]sx?$" : " babel-jest"
You can’t perform that action at this time.
0 commit comments