Live views fail on www host

Hello,

I have a live view project, hosted on fly.io.
I’ve bought a domain and set its A record to fly.io IPV4 address, as well as AAAA record to IPV6. Then, I also added CNAME record to enable www support.

Now, the website works perfectly on https://domain.com.
But when I go to https://www.domain.com, it breaks.

The home page has several buttons:

  • some of them are hrefs, leading to other live views; the work fine (as far as I get it, the http request is made when I press them and the live view’s web socket is connected afterwards)
  • others have phx-click binding, that then does push_navigate; this fail (as far as I get it, the web socket tries to do the navigation).
    Console shows me this error:
    WebSocket connection to 'wss://www.domain.com/live/websocket?_csrf_token=...' failed: There was a bad response from the server.

What could be the problem here?

Apparently, the solution is to add both domain and subdomain to check_origin in prod.exs:

config :my_app, MyAppWeb.Endpoint,
  cache_static_manifest: "priv/static/cache_manifest.json",
  check_origin: ["//domain.com", "//www.domain.com"]
1 Like