From 5386f322b83b063439f555dc115021f10b2b08a0 Mon Sep 17 00:00:00 2001 From: Jacob Paris Date: Wed, 19 Jan 2022 06:39:49 -0500 Subject: [PATCH] Launch server as localhost instead of 127.0.0.1 (#181) Unless there's any strong reason to prefer the IP address over `localhost` that I'm not privy to, I'd like to propose changing wrangler to announce the server starting as localhost instead Browsers can't set cookies to IP addresses, so any login or session tracking that a project might want to do won't work until the user switches to localhost, which can be the cause for some confusion if the dev isn't already familiar with that behaviour. Co-authored-by: Greg Brimble --- packages/wrangler/src/pages.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/wrangler/src/pages.tsx b/packages/wrangler/src/pages.tsx index 55aecf50d97c..e6300fc6a5bc 100644 --- a/packages/wrangler/src/pages.tsx +++ b/packages/wrangler/src/pages.tsx @@ -897,7 +897,7 @@ export const pages: BuilderCallback = (yargs) => { if (proxyPort) { try { const url = new URL(request.url); - url.host = `127.0.0.1:${proxyPort}`; + url.host = `localhost:${proxyPort}`; return await fetch(url, request); } catch (thrown) { console.error(`Could not proxy request: ${thrown}`); @@ -935,10 +935,10 @@ export const pages: BuilderCallback = (yargs) => { try { // `startServer` might throw if user code contains errors const server = await miniflare.startServer(); - console.log(`Serving at http://127.0.0.1:${port}/`); + console.log(`Serving at http://localhost:${port}/`); if (process.env.BROWSER !== "none") { - const childProcess = await open(`http://127.0.0.1:${port}/`); + const childProcess = await open(`http://localhost:${port}/`); // fail silently if the open command doesn't work (e.g. in GitHub Codespaces) childProcess.on("error", (_err) => {}); }