shotleybuilder
Hi
Just after the ‘secret sauce’ to get my links working correctly after the app is deployed. They all stubbornly display localhost
Here’s where I’ve been with prod.exs
url: ["${APP_NAME}.gigalixirapp.com"] I’m deploying with mix not distillery and I think this is the config for the latter
APP_NAME is available by default, and so I tried
url: ["#{System.get_env("APP_NAME")}.gigalixirapp.com"] but no luck
and of course
url: ["example.com"] which is where I started from
At a loss to know what to try next. Something so simple seems very opaque in the docs and it’s not always clear with other resources which of the three deploy methods the author is using. And lots of the help resources are now dated.
Not sure to include PORT or not. Sometimes it’s included and other times not. I have this in prod.exs too
http: [port: {:system, "PORT"}]
Any help welcomed.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
This is what I deploy to gigalixir using releases.
Generally you should not need to configure
url: [host: …]unless you’re usingMyAppWeb.Endpointfor url generation (of non-relative paths) instead of aconn. The latter does hold the current request host and simply uses that one.shotleybuilder
Oh
I use MyAppWeb.Endpoint when I use a path helper (Routes) to create a url to display.
Not so many though, so I’ll refactor and use the conn instead and hope that’ll fix it.
Thanks!
shotleybuilder
Changed my url generating code to use conn instead of MyAppWeb.Endpoint.
From:
Routes.v1_authentication_url(MyAppWeb.Endpoint, :register)To:
Routes.v1_authentication_url(conn, :register)Switched
prod.exsback from whence it cameurl: [nil, port: 80],Behaviour of deployed app unchanged
http://localhost/api/v1/registerThe config follows the docs
“Whenever possible prefer to pass a
conn(or@connin your views) in place of anEndpoint.”shotleybuilder
Hmmm,
On the server
IO.inspect(conn.host)app_name.gigalixir.com (also set in the req headers)
But,
IO.inspect(Routes.v1_authentication_url(conn, :register))http://localhost/…
I’m clearly missing something fundamental to how the path helpers work … will investigate
shotleybuilder
Phoenix.Router.Helpersmatches on%Conn{private: private}. There are 2 possibles for private either%{phoenix_router_url: _}or%{phoenix_endpoint: _}.My
connonly hasphoenix_endpointset. The upshot is a call toendpoint.url()inPhoenix.Endpoint. Which gets it’s info fromprod.exsand defaults to[host: "localhost", path: "/"]So, I’m still no further forward. I’m not sure how
url [nil, port:80]in the Gigalixir docs works - clearly in my case it doesn’t.I need my links to work, so I’m going to fallback to simply String replacing with a hardcoded app name on the result of the helper. If anyone can throw light on why my config doesn’t work I’d be interested to learn more.
LostKobrakai
Maybe I was wrong with the host of the conn being picked up. The one app I have in production with urls (emails) needs to deal with subdomains, so I have handling for that anyways.
If all you have is one domain you can set it to
url: [host: "wherever_domain.com"]. That’s at least better than using some string replacement.shotleybuilder
I’ve had to literally replace localhost with this tiny helper to make progress. Would like the permanent fix, but this works.
shotleybuilder
I did try that among the various options - just hard coding the Gigalixir app name like that. But it didn’t get picked up. There must be something else that’s wrong somewhere. Time to move on
LostKobrakai
Are you sure you added it to
url: […]and nothttp: []? The:urlconfig is meant for that exact case.shotleybuilder
I’m never sure when it comes to deployment, but happens you’re right! I thought I’d tried that, but clearly I hadn’t. Thanks for making me persist +1