Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: deno serve --host localhost prints invalid URL #23650

Open
marvinhagemeister opened this issue May 2, 2024 · 8 comments
Open

Bug: deno serve --host localhost prints invalid URL #23650

marvinhagemeister opened this issue May 2, 2024 · 8 comments
Assignees
Labels
bug Something isn't working important for fresh serve

Comments

@marvinhagemeister
Copy link
Contributor

When passing --host localhost to deno serve, the CLI will print an invalid URL: http://::1:8000/

Steps to reproduce

// main.ts
export default {
  fetch(_req) {
    return new Response("it works");
  },
};

Then run deno serve --host localhost main.ts

CLI output

$ deno serve --host localhost main.ts 
deno serve: Listening on http://::1:8000/

Version: Deno 1.43.1

@marvinhagemeister marvinhagemeister added bug Something isn't working serve labels May 2, 2024
@mmastrac
Copy link
Member

mmastrac commented May 2, 2024

@marvinhagemeister is this Linux or Mac? It looks like the socket address is being resolved here which is a bit strange.

@marvinhagemeister
Copy link
Contributor Author

@mmastrac I'm on macOS

@marvinhagemeister
Copy link
Contributor Author

Turns out that the issue can be reproduced with Deno.serve alone:

Deno.serve({ hostname: "localhost" }, () => new Response("foo"));

Output:

$ deno run -A foo.ts
Listening on http://::1:8000/

@mmastrac
Copy link
Member

mmastrac commented May 2, 2024

@marvinhagemeister What do you have in /etc/hosts (cat /etc/hosts | grep "localhost")? Also, do you have IPv6 configured under your network settings?

I wonder if this is a weird IPv6 resolution thing.

@marvinhagemeister
Copy link
Contributor Author

marvinhagemeister commented May 3, 2024

The default host file on macOS looks like this:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255	broadcasthost
::1             localhost

@dsherret
Copy link
Member

dsherret commented May 4, 2024

Just ran into this on Windows. In v1.42.3 it prints localhost and in 1.43.1 it prints "::1"

Deno.serve({
  hostname: "localhost",
  onListen(details) {
    console.log(details);
  },
}, (request) => {
  return new Response(null);
})

@dsherret
Copy link
Member

dsherret commented May 4, 2024

It also occurs on Linux and Mac: https://github.com/dsherret/dax/actions/runs/8951547585/job/24587971522

@AverageHelper
Copy link

AverageHelper commented May 7, 2024

Seems to also occur with Deno.serve in macOS and Deno 1.43.1:

// index.ts
Deno.serve({ hostname: "localhost" }, /* handler */);

Then deno run --allow-net index.ts prints http://::1:8000/

As an aside, pasting the given URL into Firefox results in a web search, rather than an attempt to connect to the local webserver as expected. According to RFC2732, the URL should instead be rendered as http://[::1]:8000/. Adding these brackets around the IPv6 address causes browsers to behave as expected.

@bartlomieju bartlomieju self-assigned this May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working important for fresh serve
Projects
None yet
Development

No branches or pull requests

5 participants