[bun dev] Automatically set origin - improve support for proxying Bun

Previously, when running Bun behind a reverse proxy, you had to pass an explicit `--origin` arg and it could only run behind one proxy at a time.

Now, Bun automatically determines the origin from the request if possible. It reads `Forwarded`, `X-Forwarded-Proto`, `X-Forwarded-Host`, `Origin`, and lastly `Host`. If none are available, it falls back to the `--origin` CLI arg.

This change is important for usecases like Replit which shows multiple iframes in different origins.
This commit is contained in:
Jarred Sumner
2022-01-01 18:12:57 -08:00
parent e4693b8aaf
commit 6a28cfd2ba
8 changed files with 247 additions and 64 deletions

View File

@@ -390,11 +390,12 @@ pub fn getScriptSrcString(
&entry_point_tempbuf,
Fs.PathName.init(file_path),
),
VirtualMachine.vm.origin,
ScriptSrcStream.Writer,
writer,
);
} else {
JavaScript.Bun.getPublicPath(file_path, ScriptSrcStream.Writer, writer);
JavaScript.Bun.getPublicPath(file_path, VirtualMachine.vm.origin, ScriptSrcStream.Writer, writer);
}
}