@@ -38,7 +38,7 @@ import { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin'
38
38
import { recursiveReadDirSync } from './lib/recursive-readdir-sync'
39
39
import { format as formatUrl , UrlWithParsedQuery } from 'url'
40
40
import compression from 'next/dist/compiled/compression'
41
- import Proxy from 'next/dist/compiled/http-proxy'
41
+ import HttpProxy from 'next/dist/compiled/http-proxy'
42
42
import { route } from './router'
43
43
import { run } from './web/sandbox'
44
44
@@ -73,6 +73,7 @@ import { loadEnvConfig } from '@next/env'
73
73
import { getCustomRoute } from './server-route-utils'
74
74
import { urlQueryToSearchParams } from '../shared/lib/router/utils/querystring'
75
75
import ResponseCache from '../server/response-cache'
76
+ import { clonableBodyForRequest } from './body-streams'
76
77
77
78
export * from './base-server'
78
79
@@ -485,7 +486,7 @@ export default class NextNodeServer extends BaseServer {
485
486
parsedUrl . search = stringifyQuery ( req , query )
486
487
487
488
const target = formatUrl ( parsedUrl )
488
- const proxy = new Proxy ( {
489
+ const proxy = new HttpProxy ( {
489
490
target,
490
491
changeOrigin : true ,
491
492
ignorePath : true ,
@@ -1236,6 +1237,11 @@ export default class NextNodeServer extends BaseServer {
1236
1237
1237
1238
const allHeaders = new Headers ( )
1238
1239
let result : FetchEventResult | null = null
1240
+ const method = ( params . request . method || 'GET' ) . toUpperCase ( )
1241
+ let originalBody =
1242
+ method !== 'GET' && method !== 'HEAD'
1243
+ ? clonableBodyForRequest ( params . request . body )
1244
+ : undefined
1239
1245
1240
1246
for ( const middleware of this . middleware || [ ] ) {
1241
1247
if ( middleware . match ( params . parsedUrl . pathname ) ) {
@@ -1245,7 +1251,6 @@ export default class NextNodeServer extends BaseServer {
1245
1251
}
1246
1252
1247
1253
await this . ensureMiddleware ( middleware . page , middleware . ssr )
1248
-
1249
1254
const middlewareInfo = this . getMiddlewareInfo ( middleware . page )
1250
1255
1251
1256
result = await run ( {
@@ -1254,14 +1259,15 @@ export default class NextNodeServer extends BaseServer {
1254
1259
env : middlewareInfo . env ,
1255
1260
request : {
1256
1261
headers : params . request . headers ,
1257
- method : params . request . method || 'GET' ,
1262
+ method,
1258
1263
nextConfig : {
1259
1264
basePath : this . nextConfig . basePath ,
1260
1265
i18n : this . nextConfig . i18n ,
1261
1266
trailingSlash : this . nextConfig . trailingSlash ,
1262
1267
} ,
1263
1268
url : url ,
1264
1269
page : page ,
1270
+ body : originalBody ?. cloneBodyStream ( ) ,
1265
1271
} ,
1266
1272
useCache : ! this . nextConfig . experimental . runtime ,
1267
1273
onWarning : ( warning : Error ) => {
@@ -1298,6 +1304,8 @@ export default class NextNodeServer extends BaseServer {
1298
1304
}
1299
1305
}
1300
1306
1307
+ originalBody ?. finalize ( )
1308
+
1301
1309
return result
1302
1310
}
1303
1311
0 commit comments