From 975c10f28ff2a95357e346fd06052bb111213b52 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Sun, 10 Dec 2023 16:31:10 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20replace=20host=20header=20to=20f?= =?UTF-8?q?ix=20proxy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/src/activation/proxy.ts | 41 ++++------------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/extensions/vscode/src/activation/proxy.ts b/extensions/vscode/src/activation/proxy.ts index 5cae543aa..7b482d435 100644 --- a/extensions/vscode/src/activation/proxy.ts +++ b/extensions/vscode/src/activation/proxy.ts @@ -8,24 +8,18 @@ const app = express(); app.use(cors()); app.use((req, res, next) => { - // Don't proxy the /sw route - if (req.path === "/sw" || req.path === "/service-worker.js") { - return next(); - } - - if (!req.headers["x-continue-url"]) { - // Just let the request through - return next(); - } - // Proxy the request - const { origin, ...headers } = req.headers; + const { origin, host, ...headers } = req.headers; const url = req.headers["x-continue-url"] as string; + const parsedUrl = new URL(url); const protocolString = url.split("://")[0]; const protocol = protocolString === "https" ? https : http; const proxy = protocol.request(url, { method: req.method, - headers: headers, + headers: { + ...headers, + host: parsedUrl.host, + }, }); proxy.on("response", (response) => { @@ -59,29 +53,6 @@ app.use((req, res, next) => { // proxy(req, res, next); // }); -app.get("/sw", (req, res) => { - // Send a script that will register the service worker - res.send( - `` - ); -}); - -app.get("/service-worker.js", (req, res) => { - // Send the service worker script - res.sendFile("/service-worker.js", { root: __dirname }); -}); - export function startProxy() { app.listen(PROXY_PORT, () => { console.log(`Proxy server is running on port ${PROXY_PORT}`);