I have a simple node.js server running on port 8080 with socket.io with the code from here What is an example of the simplest possible Socket.io example?.
When I connect with curl, it works fine:
curl -vk http://www.example.com:8080
* Connected to www.example.com (123.456.789.123) port 8080 (#0)
When I browse using Chrome 70.0.3538.110 on Mac to http://www.example.com:8080 it just keeps loading until I get ERR_CONNECTION_TIMED_OUT
. I get the same result in Safari.
However, when I browse directly to the IP like this http://123.456.789.123:8080 it works right away.
Why can this be? The domain points to the right IP, and apparently it works in curl, and also wget. Is there any header missing or something else that browsers need?
I found something on a differentabout accept header, that might be related:
The reason it doesn't work from your browser is probably that it sends an accept header something like:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,\*/\*;q=0.8
Whereas curl (and presumably the Chrome extension) asks for:
Accept: \*/\*
However, the index.js has res.writeHead(200, {'Content-Type': 'text/html'});
so I think it should send a proper header. Also it works in the browser with the IP, so it might not be related to this.
How can I fix this?