@@ -214,6 +214,10 @@ export const handler = async function () {
214
214
path : 'public/index.html' ,
215
215
content : 'index' ,
216
216
} )
217
+ . withContentFile ( {
218
+ path : 'public/origin.html' ,
219
+ content : 'origin' ,
220
+ } )
217
221
. withRedirectsFile ( {
218
222
redirects : [ { from : `/api/*` , to : `/.netlify/functions/:splat` , status : '200' } ] ,
219
223
} )
@@ -226,15 +230,21 @@ export const handler = async function () {
226
230
} )
227
231
. withEdgeFunction ( {
228
232
handler : async ( req , { next } ) => {
229
- if ( ! req . url . includes ( '?ef=true' ) ) {
230
- return
233
+ if ( req . url . includes ( '?ef=true' ) ) {
234
+ // eslint-disable-next-line n/callback-return
235
+ const res = await next ( )
236
+ const text = await res . text ( )
237
+
238
+ return new Response ( text . toUpperCase ( ) , res )
231
239
}
232
240
233
- // eslint-disable-next-line n/callback-return
234
- const res = await next ( )
235
- const text = await res . text ( )
241
+ if ( req . url . includes ( '?ef=fetch' ) ) {
242
+ const url = new URL ( '/origin' , req . url )
243
+ const res = await fetch ( url )
244
+ const text = await res . text ( )
236
245
237
- return new Response ( text . toUpperCase ( ) , res )
246
+ return new Response ( text . toUpperCase ( ) , res )
247
+ }
238
248
} ,
239
249
name : 'hello' ,
240
250
} )
@@ -248,6 +258,7 @@ export const handler = async function () {
248
258
const options = { https : { rejectUnauthorized : false } }
249
259
t . is ( await got ( `https://localhost:${ port } ` , options ) . text ( ) , 'index' )
250
260
t . is ( await got ( `https://localhost:${ port } ?ef=true` , options ) . text ( ) , 'INDEX' )
261
+ t . is ( await got ( `https://localhost:${ port } ?ef=fetch` , options ) . text ( ) , 'ORIGIN' )
251
262
t . deepEqual ( await got ( `https://localhost:${ port } /api/hello` , options ) . json ( ) , {
252
263
rawUrl : `https://localhost:${ port } /api/hello` ,
253
264
} )
0 commit comments