slouchpie

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:

  1. Is there some config I can change to make Elixir releases on Gigalixir use correct base path for URLs?
  2. Is there some way to “hijack” the URL-generating function that will let me replace “localhost” string?

Thanks in advance.

Most Liked

josevalim

josevalim

Creator of Elixir

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

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

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

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.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement