shotleybuilder

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.

Showing Posts 1 to 10

LostKobrakai

LostKobrakai

# prod.exs
config :bob_versions_web, BobVersionsWeb.Endpoint,
  http: [:inet6, port: System.get_env("PORT") || 4000],
  url: [scheme: "https", port: 443],
  force_ssl: [rewrite_on: [:x_forwarded_proto], host: nil],
  check_origin: ["//*.kobrakai.de", "//*.gigalixirapp.com"]

# releases.exs
config :bob_versions_web, BobVersionsWeb.Endpoint,
  secret_key_base: System.fetch_env!("SECRET_KEY_BASE")

This is what I deploy to gigalixir using releases.

Generally you should not need to configure url: [host: …] unless you’re using MyAppWeb.Endpoint for url generation (of non-relative paths) instead of a conn. The latter does hold the current request host and simply uses that one.

shotleybuilder

shotleybuilder OP

Oh :slight_smile:

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

shotleybuilder OP

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.exs back from whence it came
url: [nil, port: 80],

Behaviour of deployed app unchanged :frowning:
http://localhost/api/v1/register

The config follows the docs

“Whenever possible prefer to pass a conn (or @conn in your views) in place of an Endpoint .”

shotleybuilder

shotleybuilder OP

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

shotleybuilder OP

Phoenix.Router.Helpers matches on %Conn{private: private}. There are 2 possibles for private either %{phoenix_router_url: _} or %{phoenix_endpoint: _}.

My conn only has phoenix_endpoint set. The upshot is a call to endpoint.url() in Phoenix.Endpoint. Which gets it’s info from prod.exs and 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

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

shotleybuilder OP

I’ve had to literally replace localhost with this tiny helper to make progress. Would like the permanent fix, but this works.

def route(route) do
case Mix.env() do
:prod →
String.replace_leading(route,“http://localhost”, “https://my-app-name.gigalixirapp.com”)
_ → route
end
end

shotleybuilder

shotleybuilder OP

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 :slight_smile:

LostKobrakai

LostKobrakai

Are you sure you added it to url: […] and not http: []? The :url config is meant for that exact case.

shotleybuilder

shotleybuilder OP

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

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews