diff --git a/config/runtime.exs b/config/runtime.exs index 955297b..57630b0 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -80,19 +80,11 @@ if config_env() == :prod do origins -> String.split(origins, ",", trim: true) end - force_ssl = - case System.get_env("PHX_FORCE_SSL") do - "false" -> false - "reverse_proxy" -> [hsts: true, rewrite_on: [:x_forwarded_proto]] - _ -> [hsts: true] - end - config :atjams, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY") config :atjams, AtjamsWeb.Endpoint, url: [host: host, port: 443, scheme: "https"], check_origin: check_origin, - force_ssl: force_ssl, http: [ # Enable IPv6 and bind on all interfaces. # Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access. diff --git a/lib/atjams/application.ex b/lib/atjams/application.ex index 839d110..5012852 100644 --- a/lib/atjams/application.ex +++ b/lib/atjams/application.ex @@ -28,7 +28,7 @@ defmodule Atjams.Application do restart: :permanent, shutdown: 500 }, - AtjamsWeb.Endpoint + {AtjamsWeb.Endpoint, force_ssl: AtjamsWeb.Endpoint.force_ssl_config()} ] # See https://hexdocs.pm/elixir/Supervisor.html diff --git a/lib/atjams_web/endpoint.ex b/lib/atjams_web/endpoint.ex index 5983f36..c2df2c3 100644 --- a/lib/atjams_web/endpoint.ex +++ b/lib/atjams_web/endpoint.ex @@ -55,4 +55,12 @@ defmodule AtjamsWeb.Endpoint do plug Plug.Head plug Plug.Session, @session_options plug AtjamsWeb.Router + + def force_ssl_config do + case System.get_env("PHX_FORCE_SSL") do + "false" -> false + "reverse_proxy" -> [hsts: true, rewrite_on: [:x_forwarded_proto]] + _ -> [hsts: true] + end + end end