@@ -7,6 +7,7 @@ const path = require('path')
77// eslint-disable-next-line ava/use-test
88const avaTest = require ( 'ava' )
99const { isCI } = require ( 'ci-info' )
10+ const { Response } = require ( 'node-fetch' )
1011
1112const { curl } = require ( './utils/curl' )
1213const { withDevServer } = require ( './utils/dev-server' )
@@ -194,7 +195,13 @@ export const handler = async function () {
194195 config : {
195196 build : { publish : 'public' } ,
196197 functions : { directory : 'functions' } ,
197- dev : { https : { certFile : 'cert.pem' , keyFile : 'key.pem' } } ,
198+ dev : { https : { certFile : 'localhost.crt' , keyFile : 'localhost.key' } } ,
199+ edge_functions : [
200+ {
201+ function : 'hello' ,
202+ path : '/' ,
203+ } ,
204+ ] ,
198205 } ,
199206 } )
200207 . withContentFile ( {
@@ -211,15 +218,30 @@ export const handler = async function () {
211218 body : 'Hello World' ,
212219 } ) ,
213220 } )
221+ . withEdgeFunction ( {
222+ handler : async ( req , { next } ) => {
223+ if ( ! req . url . includes ( '?ef=true' ) ) {
224+ return
225+ }
226+
227+ // eslint-disable-next-line n/callback-return
228+ const res = await next ( )
229+ const text = await res . text ( )
230+
231+ return new Response ( text . toUpperCase ( ) , res )
232+ } ,
233+ name : 'hello' ,
234+ } )
214235 . buildAsync ( )
215236
216237 await Promise . all ( [
217- copyFile ( `${ __dirname } /assets/cert.pem ` , `${ builder . directory } /cert.pem ` ) ,
218- copyFile ( `${ __dirname } /assets/key.pem ` , `${ builder . directory } /key.pem ` ) ,
238+ copyFile ( `${ __dirname } /../../localhost.crt ` , `${ builder . directory } /localhost.crt ` ) ,
239+ copyFile ( `${ __dirname } /../../localhost.key ` , `${ builder . directory } /localhost.key ` ) ,
219240 ] )
220241 await withDevServer ( { cwd : builder . directory , args } , async ( { port } ) => {
221242 const options = { https : { rejectUnauthorized : false } }
222243 t . is ( await got ( `https://localhost:${ port } ` , options ) . text ( ) , 'index' )
244+ t . is ( await got ( `https://localhost:${ port } ?ef=true` , options ) . text ( ) , 'INDEX' )
223245 t . is ( await got ( `https://localhost:${ port } /api/hello` , options ) . text ( ) , 'Hello World' )
224246 } )
225247 } )
0 commit comments