Skip to content

Commit

Permalink
Launch server as localhost instead of 127.0.0.1 (#181)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jacobparis and GregBrimble authored Jan 19, 2022
1 parent e22f9d7 commit 5386f32
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/wrangler/src/pages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ export const pages: BuilderCallback<unknown, unknown> = (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}`);
Expand Down Expand Up @@ -935,10 +935,10 @@ export const pages: BuilderCallback<unknown, unknown> = (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) => {});
}
Expand Down

0 comments on commit 5386f32

Please sign in to comment.