gaynetdinov / ex_money

An [abandoned] self-hosted personal finance app
ISC License
168 stars 12 forks source link

Fix HOME_URL var access #69

Closed MarSoft closed 7 years ago

MarSoft commented 8 years ago

When I tried to follow instructions to deploy on Heroku, I kept getting a redirect to "https://localhost" instead of any site page. In build log there was this warning:

remote:        Will export the following config vars:
remote:        * Config vars DATABASE_URL
remote:        * MIX_ENV=prod
...
remote: -----> Copying hex from /app/.mix/archives/hex-0.13.2
remote: -----> Compiling
remote: Compiling 75 files (.ex)
remote: warning: you have enabled :force_ssl but your host is currently set to localhost.
remote: Please configure your endpoint url host properly:
remote:
remote:     config ExMoney.Endpoint, url: [host: "YOURHOST.com"]
remote:

So I updated config to export HOME_URL var as well, and this worked. Am I doing something wrong?

gaynetdinov commented 8 years ago

Hello. Thanks for the issue!

I wrote these instructions a long time ago, so to be honest, I don't remember all the details. But looking at my instructions now I see that it contains a bullet about setting HOME_URL.

screen shot 2016-10-23 at 21 48 15

And the prod environment really relies on it https://github.com/gaynetdinov/ex_money/blob/master/config/prod.exs#L16

Did you set HOME_URL correctly while following the instructions?

MarSoft commented 8 years ago

Yes, I did set the variable. But looks like it is not passed to the buildpack unless specifically allowed by the config. And when buildpack cannot see this var, it will do something wrong - and as a result, deployed app keeps redirecting to localhost.

But strange enough, I couldn't reproduce it when using auto-deploy. I have partially implemented Deploy with Heroku button, it is still not fully functional (it doesn't configure task with Heroku Scheduler).

MarSoft commented 8 years ago

Hm, interesting. Just checked without the fix. When you open newly created app with https:// protocol, it works & asks you to create new user. But if you try to open it with http:// url then you are redirected to https://localhost. I don't know why, as I am not familiar with Elixir. With my fix though, HOME_URL variable is respected, but only at the time of building. So if you change it with heroku config:set HOME_URL=something.different, that change will not be applied until you rebuild an app by pushing new version. Probably there is some better solution?

gaynetdinov commented 8 years ago

So the issue is that http://ex-money-heroku-url.com doesn't work(redirects to localhost), but https://ex-money-heroku-url.com works, right? It seems like it redirects http to localhost, because url for port 80 is not set, in config/prod.exs only port 443 is configured. I don't really know how to configure config/prod.exs to make phoenix serve both 80 and 443 ports and to be honest, I don't see any reason why you'd do that(I mean accessing ex_money without https).

As for buildpack.config, I think you're right. You need to specify all system ENVs in config_vars_to_export to make them accessible via Application.get_env(:ex_money, :my_var). References https://medium.com/@chibicode/some-gotchas-when-deploying-a-elixir-phoenix-app-to-heroku-6ae668d1667d#.jtkj9neib http://wsmoak.net/2015/07/05/phoenix-on-heroku.html