slouchpie
Gigalixir "elixir release" not generating correct URLs
In a normal Phoenix app. the Router.Helpers generate correct urls, e.g.
Routes.user_confirmation_url(conn, :confirm, token)
will output https://myapp.com/user/confirm/?token=token.
When I deploy an app to Gigalixir using Elixir releases, I have to specify (as per docs https://gigalixir.readthedocs.io/en/latest/modify-app/releases.html#modifying-existing-app-with-elixir-releases):
url: [host: nil, port: 443]
in config/releases.exs.
And this results in incorrect URLs being generated (they come out as https://localhost:443/user/confirm/?token-token).
I can workaround this for now, by setting a new ENV var, say, BASE_PATH=https://myapp.com and generating URLs like this:
Routes.user_confirmation_url(%URI{path: System.get_env("BASE_PATH"), :confirm, token)
but I don’t like having to repeat this code in many places.
So I have 2 questions:
- Is there some config I can change to make Elixir releases on Gigalixir use correct base path for URLs?
- Is there some way to “hijack” the URL-generating function that will let me replace “localhost” string?
Thanks in advance.
Most Liked
josevalim
I don’t understand why they are asking to set it to nil, perhaps you should e-mail support and ask for clarifications.
The thing is most apps are running behind a proxy, Gigalixir is no different, and inside the proxy, you are typically running on localhost. So here is how it works:
[browser] -- app.gigalixir.com --> [proxy] -- localhost --> [yourapp]
So if you don’t configure the host, the app is correct in thinking it is running on localhost. We could use the X_FORWARDED_FOR headers to figure out the actual host but that has security implications when read and it is not behind a proxy. So my suggestion is to explicitly set the :host to your actual host instead of nil in your config files. You can either hardcode it or use an environment variable.
TL;DR: don’t use nil, set it to your actual host.
jesse
Oops, I think you’re right. I think host should be nil in the force_ssl setting, not the url setting. I’ll update the docs. Thanks for letting me know.
LostKobrakai
This is because the config is not the only place do derive the domain from, but it might just be wrong in telling you to set it to nil. It likely should just skip the :host key completely.
The conn does hold the domain the app is accessed by, which is then used by the helper to build up the full url. This is especially useful for places like gigalixir, where it’s likely that the app is accessable via multiple domains. What this will prevent however is using MyApp.Endpoint with those helpers to create full urls.
There is a place, which needs an explicit host: nil, which is for force_ssl:
luckywatcher
To be clear, I didn’t intend for you to prepend System.get_env("BASE_PATH") everywhere it is needed. Centralizing where it is done (in a module) is fine.
I intended to suggest using the _path versions where possible – and to prepend to _path if needed.








