Deploy to Fly.io using custom domain not working?

Hey guys!

I have deployed my Phoenix project to Fly here and set up my DNS records and certs in order to connect to my custom domain here but something is broken.

The fly.dev url works perfectly, but even though my custom domain displays my test text it also throws a “Something went wrong” error..

Fly.io logs say this:

[error] Could not check origin for Phoenix.Socket transport.
[info] Origin of the request: https://wordsmith.pub
[info] This happens when you are attempting a socket connection to
[info] a different host than the one configured in your config/
[info] files. For example, in development the host is configured
[info] to “localhost” but you may be trying to access it from
[info] “127.0.0.1”. To fix this issue, you may either:
[info] 1. update [url: [host: …]] to your actual host in the
[info] config file for your current environment (recommended)
[info] 2. pass the :check_origin option when configuring your
[info] endpoint or when configuring the transport in your
[info] UserSocket module, explicitly outlining which origins
[info] are allowed:
[info] check_origin: [“https://example.com”,
[info] “//another.com:888”, “//other.com”]

I tried to do step 1 by changing the config.exs file in my Phoenix project to add url: [host: "wordsmith.pub"], but that didn’t fix anything and I don’t know how to do the second suggestion.

I didn’t see any documentation on Fly indicating I would have to change my Phoenix files in order to deploy to a custom domain, so I’m not sure what to try next.

My first thought is that this is some kind of DNS record propagation issue. I added the certs and DNS records pointing to the custom domain yesterday morning. So let me know if I simply need to wait longer!

Thanks!

add check_origin: ["https://wordsmith.pub"] under the url key in the endpoint configuration.

Also, in the docs they mention setting a CNAME as the simplest route.

is there any reason you didn’t go that route? That’s what I’ve done a couple of times.

Your original issue will be fixed with the check_origin key though :slight_smile:

Pretty sure I tried the CNAME option first and messed it up haha so I thought it didn’t work for me. So to answer your question, inexperience.

Thanks for the idea! I actually just tried one last thing and got it working by going into the fly.toml file and changing the PHX_HOST variable from the fly.dev server to my “wordsmtih.pub” domain. Reran fly deploy and it seems to be working beautifully.

Thanks for the suggestion! We can probably mark this thread closed.

I was too hasty in calling it solved!

Changing the PHX_HOST variable to “Wordsmith.pub” definitely fixed by custom domain, but at the cost of breaking the “wordsmith-lml.fly.dev” one.

I was able to get the fly.dev one back working though by adding your check origin suggestion.

In my Phoenix Project, config/config.exs file I added both URLs:

config :wordsmith, WordsmithWeb.Endpoint,
  url: [host: "localhost"],
  check_origin: ["https://wordsmith.pub","https://wordsmith-lml.fly.dev"],
  adapter: Bandit.PhoenixAdapter,
  render_errors: [
    formats: [html: WordsmithWeb.ErrorHTML, json: WordsmithWeb.ErrorJSON],
    layout: false
  ],
  pubsub_server: Wordsmith.PubSub,
  live_view: [signing_salt: "E1HLgpGK"]

So the current state is:

  • PHX_HOST variable in the fly.toml file is set to “wordsmith.pub”
  • I added both URLs to a check origin line.

Let me know if that is totally unkosher! It seems to be working.