Phoenix application behind AWS ALB

So, you mean to add to url in runtime.exs the following:

config :api_baas, ApiBaasWeb.Endpoint,
    url: [host: apibaas.io/myapp, port: 443, scheme: "https"],

If this works I was not aware, and that’s solves the problem really well.


I totally forgot about this old proof of concept of mine:

https://github.com/Exadra37/elixir-phoenix-360-web-apps/blob/dev_runtime-wip/TRY_IT_OUT.md

In this PoC you can also find this approach to handle this path situation:

# file: ./phoenix360/config/runtime.exs

config :phoenix360, Phoenix360Web.Endpoint,
  http: [
    port: phoenix360_http_port,
    transport_options: [socket_opts: [:inet6]],
    # @link https://ninenines.eu/docs/en/cowboy/2.7/guide/routing/
    dispatch: [
      {
        phoenix360_host,
        [
          # @PHOENIX_360_WEB_APPS - Each included 360 web app needs to have an
          #   endpoint in the top level 360 web app. This is necessary in order
          #   for the top level 360 web app to know how to dispatch the requests.
          #   For example a request to app.local/_links/* will be dispatched to
          #   the `/links/*` endpoint for the LinksWeb.Router.
          #
          # {:path_match, :handler, :initial_state}
          {"/_links/[...]", Phoenix.Endpoint.Cowboy2Handler, {LinksWeb.Endpoint, []}},
          {"/_notes/[...]", Phoenix.Endpoint.Cowboy2Handler, {NotesWeb.Endpoint, []}},

          # @PHOENIX_360_WEB_APPS - This tells that all other request must be
          #   dispatched to the Phoenix360Web.Router, aka the one for the top
          #   level 360 web app.
          {:_, Phoenix.Endpoint.Cowboy2Handler, {Phoenix360Web.Endpoint, []}},
        ]
      },
      {
        links_host,
        [
          # {:path_match, :handler, :initial_state}
          {:_, Phoenix.Endpoint.Cowboy2Handler, {LinksWeb.Endpoint, []}},
        ]
      },
      {
        notes_host,
        [
          # {:path_match, :handler, :initial_state}
          {:_, Phoenix.Endpoint.Cowboy2Handler, {NotesWeb.Endpoint, []}},
        ]
      }
    ]
  ]

# @PHOENIX_360_WEB_APPS - No need to have a server running for `:links`, because
#    the requests will be handled by the Cowboy server for the main 360 web app
#    `phoenix360`:
config :links, LinksWeb.Endpoint,
  server: false

# @PHOENIX_360_WEB_APPS - No need to have a server running for `:notes`, because
#    the requests will be handled by the Cowboy server for the main 360 web app
#    `phoenix360`:
config :notes, NotesWeb.Endpoint,
  server: false

The project contains a full step by step to reproduce a working example.