Elixir Phoenix - Websocket error with custom domain

Hi,

I got a slightly odd bug when adding a custom domain to my Fly.io app.

I have the app deployed to https://floral-mountain-3062.fly.dev/ and it works well.

Today I bought a custom domain https://backcaster.app/ . I followed the instructions on SSL for Custom Domains and all seemed well.

The DNS is working and it loads the page, however, I am having issues getting the Websocket to connect. I am seeing this error in the console:

WebSocket connection to ‘wss://backcaster.app/live/websocket?_csrf_token=KQ9BNQIiFzYFckdyT3IMRhkQfj80OEcmbX4tnUnPKA3185tq_DJIqvwy&_track_static%5B0%5D=https%3A%2F%2Fbackcaster.app%2Fassets%2Fapp.css&_track_static%5B1%5D=https%3A%2F%2Fbackcaster.app%2Fassets%2Fapp.js&_mounts=0&vsn=2.0.0’ failed:

I cannot currently use the site in the current state. The console does not give much more info. Any help would be much appreciated.

Regards

Tom

Update:

So I managed to fix this, if it helps anyone else, it was due to the Endpoint Config in runtime.exs

I had to update the url:

url: [host: "backcaster.app", port: 80]
2 Likes

Ahhh this is a good catch. Phoenix 1.6.4 supports specifying the domain as an environment variable, so it’ll be a little more obvious what to do here on new apps.

1 Like

I totally forgot about changing the host when adding my custom domain! I updated it in the fly.toml file instead of editing runtime.exs

1 Like