Skip to content

Instantly share code, notes, and snippets.

@mveytsman
Last active March 18, 2021 18:58
Show Gist options
  • Save mveytsman/f3b4a24490853b3fabfae8a633ac48ea to your computer and use it in GitHub Desktop.
Save mveytsman/f3b4a24490853b3fabfae8a633ac48ea to your computer and use it in GitHub Desktop.
Gigalixir canonical host
defmodule GigalixirCanonicalHost do
defdelegate init(opts), to: PlugCanonicalHost
def call(conn, opts) do
# There's a bug in gigagilir where requests to foo.gigaglixirapp.com
# get `x-forwarded-proto: https` but `x-forwarded-port: 80` which messes up canonical host
conn =
if Plug.Conn.get_req_header(conn, "x-forwarded-proto") == "https" &&
Plug.Conn.get_req_header(conn, "x-forwarded-port") == "80" do
conn
|> Plug.Conn.set_req_header("x-forwarded-port", "443")
else
conn
end
opts =
PlugCanonicalHost.call(conn, opts)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment