Last active
March 18, 2023 18:11
-
-
Save damonvjanis/a7d98c8e5187b23146371fbbb55cfc41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyAppWeb.Endpoint do | |
# All the stuff we just added | |
@session_options ... | |
socket ... | |
def www_redirect(conn, _options) do | |
if String.starts_with?(conn.host, "www.#{host()}") do | |
conn | |
|> Phoenix.Controller.redirect(external: "https://#{host()}") | |
|> halt() | |
else | |
conn | |
end | |
end | |
# Redirect all www requests to the root url | |
plug :www_redirect | |
plug ... | |
plug ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment