Currently, I have a fastify app hosted on fly. I wish to add a custom domain to it, but after adding it, I’ve discovered that the site cannot be reached but was available previously with the .fly.dev
domain.
After some debugging I found out that what’s causing it was ipv4 and ipv6 not connecting to my service. The strange thing is my service is still reachable from the provided .fly.dev
domain. This is a code snippet where I configure my fastify app.
const app = fastify({
logger: true,
});
const PORT = parseInt(process.env.PORT || '4000', 10);
const HOST = PORT === 4000 ? '127.0.0.1' : '::';
...
app.listen({ port: PORT, host: HOST }).then((address) => {
console.log(`✨ server listening on ${address}`);
});
What are the DNS records you added?
EDIT: Also, which port are you listening on? It looks like that code will listen on localhost if the port is 4000? I wonder if local ports are accessible.
For the DNS I followed what is instructed when adding the domain, A record for ipv4 and AAAA record for ipv6 as well as the acme challenge record. However, I doubt the problem is related to DNS resolver, I was able to get the IP from the custom domain but the service is not responding.
The app will listen to which ever the PORT env variable is, I believe it is set to 8080 (default configuration).
No luck, I tried redeploying another fastify app with simpler setup, still having the same issue. I remember I didn’t have this problem with Go apps.
Hm, I wonder if it’s TLS related.
I set up an app to test with:
Source: Bheesham Persaud / bhee-fast · GitLab
Fly.io dev: https://bhee-fast.fly.dev/
Domain: https://fast.bhee.sh
What I noticed was before I added a certificate for my domain the requests would fail:
🐡> curl https://fast.bhee.sh/
curl: (35) error:0A000126:SSL routines::unexpected eof while reading
And now that I’ve added a certificate:
🐡> curl https://fast.bhee.sh/
{"hello":"world"}⏎
Yes, can confirm this issue, looks like the app will only respond if requested through https. I was accessing the ipv4 and ipv6 directly though http, thus not receiving any response.
However, after setting up certificate correctly, I’m able to get a response from my custom domain. It’s weird however, because if an app is hosted on a server, I would expect it to respond to the request regardless of the protocol.
Thanks @bheesham for helping me with the issue.
1 Like
A quick fix (a workaround, rather) is to set force_https=true
in the app’s fly.toml
against the handler entry: New Feature: Automatic HTTPS redirects
1 Like