Retro.ConfigHelper (Retro v2.1.0) View Source

Link to this section Summary

Functions

Extract host from url.

Parse the url of phoenix endpoint.

Link to this section Functions

Extract host from url.

Link to this function

parse_phoenix_endpoint_url(url)

View Source

Parse the url of phoenix endpoint.

When deploying Phoenix application behind a proxy, it is common to specify the :url option of Phoenix endpoint like this:

config :demo_web, DemoWeb.Endpoint,
  url: [scheme: "https", host: "example.com", port: 443, path: "/"],
  check_origin: ["https://example.com/"],
  # ...

As you can see, the config is verbose because :url and :check_origin are sharing the same pieces of data.

In order to remove this kind of verbose, we can write something like:

import Retro.ConfigHelper

base_url = "https://example.com/"

config :demo_web, DemoWeb.Endpoint,
  url: parse_phoenix_endpoint_url(base_url),
  check_origin: [base_url],
  # ...

Much better.