I was playing with Fly.io recently, and noticed something weird while deploying a Fastify server.
I had hardcoded 0.0.0.0 to listen for external incoming requests, but when I was looking at the machine logs, I can see that its replaced with 127.0.0.1, and couldn’t find any documentation around this.
This is not a blocker/issue, just curious why Fly is replacing the Host with 127.0.0.1.
I’m not sure if Fly is doing that. What does the log say when you run it locally?
local logs print 0.0.0.0, but it only shows 127.0.0.1 when deployed on fly
Maybe it’s the fly proxy that gets mapped to the localhost address. What if you print the address as a callback inside the listen function.
When I run the getting started example (choosing ESM, turning the final comment into a console.log
, adding in , host: '0.0.0.0'
, on MacOS), I get:
Server is now listening on http://127.0.0.1:3000
I’m not sure what is going on here, but it appears to be fastify itself that is changing the host, based on what it observes in the environment, which in this case probably doesn’t mean fly.io, but rather the underlying operating system specified in the FROM instruction in your Dockerfile (probably Debian Bookworm).
My bad, you guys are correct. It was Fastify printing the wrong IP.
Replacing “0.0.0.0” with “::” does the job.