1+ import http from "node:http" ;
2+ import https from "node:https" ;
13import { responseInterceptor } from "http-proxy-middleware" ;
24import _ from "lodash" ;
35import jsYaml from "js-yaml" ;
@@ -8,6 +10,17 @@ import { injectIndexHtml } from "./utils/injectIndexHtml.js";
810import { getProcessedPublicDeps } from "./utils/getProcessedPublicDeps.js" ;
911import { concatBrickPackages } from "./utils/concatBrickPackages.js" ;
1012
13+ // Create an http agent that always use IPv4
14+ let agent ;
15+ const getAgent = ( server ) => {
16+ if ( ! agent ) {
17+ agent = new ( server . startsWith ( "https:" ) ? https : http ) . Agent ( {
18+ family : 4 ,
19+ } ) ;
20+ }
21+ return agent ;
22+ } ;
23+
1124const { safeDump, JSON_SCHEMA } = jsYaml ;
1225
1326export default function getProxy ( env , getRawIndexHtml ) {
@@ -71,7 +84,11 @@ export default function getProxy(env, getRawIndexHtml) {
7184 // Reset the origin header to the remote server
7285 if (
7386 req . headers [ "origin" ] ===
74- `http${ env . https ? "s" : "" } ://${ host } :${ port } `
87+ `http${ env . https ? "s" : "" } ://${ host } :${ port } ` ||
88+ // Always reset origin when host is 0.0.0.0
89+ ( host === "0.0.0.0" &&
90+ req . headers [ "origin" ] &&
91+ req . headers [ "origin" ] !== server )
7592 ) {
7693 proxyReq . setHeader ( "origin" , server ) ;
7794 }
@@ -459,6 +476,7 @@ function getBasicProxyOptions({ baseHref, server }, subPath) {
459476 : {
460477 [ `^${ _ . escapeRegExp ( baseHref ) } ${ subPath } ` ] : `/next/${ subPath } ` ,
461478 } ,
479+ agent : getAgent ( server ) ,
462480 } ;
463481}
464482
0 commit comments