Skip to content

Commit 3b8da27

Browse files
committed
Rewrite Host header when proxying to esbuild
1 parent eef9eb1 commit 3b8da27

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

scripts/lib/dev-server.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ const EXTRA_HEADERS = {
2424
};
2525

2626
// Allowed hosts for dev server
27-
const BASE_ALLOWED_HOSTS = ['localhost', '.app.github.dev'];
27+
const ALLOWED_HOSTS = ['localhost', '.app.github.dev'];
2828

2929
function isHostAllowed(hostHeader, boundHost) {
3030
if (!hostHeader) {
3131
return false;
3232
}
3333

3434
// When binding to all interfaces, allow any host.
35-
if (boundHost === '0.0.0.0') {
35+
if (boundHost === '0.0.0.0' || boundHost === '::' || boundHost === '::0') {
3636
return true;
3737
}
3838

3939
const hostname = hostHeader.split(':')[0];
40-
const allowedHosts = [...BASE_ALLOWED_HOSTS, boundHost];
40+
const allowedHosts = [...ALLOWED_HOSTS, boundHost];
4141

4242
return allowedHosts.some((allowedHost) => {
4343
if (allowedHost.startsWith('.')) {
@@ -90,7 +90,10 @@ export async function startDevServer(buildConfig, options = {}) {
9090
port: esbuildServerPort,
9191
path: req.url,
9292
method: req.method,
93-
headers: req.headers,
93+
headers: {
94+
...req.headers,
95+
host: hostname + ':' + esbuildServerPort,
96+
},
9497
};
9598

9699
// Forward each incoming request to esbuild

0 commit comments

Comments
 (0)