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

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews