1
- import { InternalEvent , InternalResult } from "types/open-next" ;
1
+ import type { ReadableStream } from "node:stream/web" ;
2
+
3
+ import type { InternalEvent , InternalResult } from "types/open-next" ;
4
+ import { emptyReadableStream } from "utils/stream" ;
2
5
3
6
// We import it like that so that the edge plugin can replace it
4
7
import { NextConfig } from "../adapters/config" ;
@@ -8,11 +11,14 @@ import {
8
11
convertToQueryString ,
9
12
} from "../core/routing/util" ;
10
13
14
+ declare global {
15
+ var isEdgeRuntime : true ;
16
+ }
17
+
11
18
const defaultHandler = async (
12
19
internalEvent : InternalEvent ,
13
20
) : Promise < InternalResult > => {
14
- // TODO: We need to handle splitted function here
15
- // We should probably create an host resolver to redirect correctly
21
+ globalThis . isEdgeRuntime = true ;
16
22
17
23
const host = internalEvent . headers . host
18
24
? `https://${ internalEvent . headers . host } `
@@ -35,10 +41,6 @@ const defaultHandler = async (
35
41
url,
36
42
body : convertBodyToReadableStream ( internalEvent . method , internalEvent . body ) ,
37
43
} ) ;
38
-
39
- const arrayBuffer = await response . arrayBuffer ( ) ;
40
- const buffer = Buffer . from ( arrayBuffer ) ;
41
-
42
44
const responseHeaders : Record < string , string | string [ ] > = { } ;
43
45
response . headers . forEach ( ( value , key ) => {
44
46
if ( key . toLowerCase ( ) === "set-cookie" ) {
@@ -49,9 +51,9 @@ const defaultHandler = async (
49
51
responseHeaders [ key ] = value ;
50
52
}
51
53
} ) ;
52
- // console.log("responseHeaders", responseHeaders);
53
- const body = buffer . toString ( ) ;
54
- // console.log(" body", body );
54
+
55
+ const body =
56
+ ( response . body as ReadableStream < Uint8Array > ) ?? emptyReadableStream ( ) ;
55
57
56
58
return {
57
59
type : "core" ,
0 commit comments