Skip to content

Commit

Permalink
only configure runtime in prod
Browse files Browse the repository at this point in the history
  • Loading branch information
APB9785 committed Jan 15, 2025
1 parent 10ba70a commit 63cd932
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
16 changes: 8 additions & 8 deletions lib/mix/tasks/beacon.gen.proxy_endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,26 @@ defmodule Mix.Tasks.Beacon.Gen.ProxyEndpoint do
[proxy_endpoint_module_name, :live_view, :signing_salt],
signing_salt
)
|> Igniter.Project.Config.configure(
"runtime.exs",
|> Igniter.Project.Config.configure_runtime_env(
:prod,
otp_app,
[proxy_endpoint_module_name, :check_origin],
{:code, Sourceror.parse_string!("[]")}
)
|> Igniter.Project.Config.configure(
"runtime.exs",
|> Igniter.Project.Config.configure_runtime_env(
:prod,
otp_app,
[proxy_endpoint_module_name, :url],
{:code, Sourceror.parse_string!("[port: 443, scheme: \"https\"]")}
)
|> Igniter.Project.Config.configure(
"runtime.exs",
|> Igniter.Project.Config.configure_runtime_env(
:prod,
otp_app,
[proxy_endpoint_module_name, :http],
{:code, Sourceror.parse_string!("[ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: port]")}
)
|> Igniter.Project.Config.configure(
"runtime.exs",
|> Igniter.Project.Config.configure_runtime_env(
:prod,
otp_app,
[proxy_endpoint_module_name, :secret_key_base],
{:code, Sourceror.parse_string!("secret_key_base")}
Expand Down
23 changes: 14 additions & 9 deletions lib/mix/tasks/beacon.gen.site.ex
Original file line number Diff line number Diff line change
Expand Up @@ -346,19 +346,24 @@ defmodule Mix.Tasks.Beacon.Gen.Site do
""")}
)
# runtime.exs
|> Igniter.Project.Config.configure("runtime.exs", otp_app, [new_endpoint, :url, :host], host)
|> Igniter.Project.Config.configure("runtime.exs", otp_app, [new_endpoint, :url, :port], 443)
|> Igniter.Project.Config.configure("runtime.exs", otp_app, [new_endpoint, :url, :scheme], "https")
|> Igniter.Project.Config.configure(
"runtime.exs",
|> Igniter.Project.Config.configure_runtime_env(:prod, otp_app, [new_endpoint, :url, :host], host)
|> Igniter.Project.Config.configure_runtime_env(:prod, otp_app, [new_endpoint, :url, :port], 443)
|> Igniter.Project.Config.configure_runtime_env(:prod, otp_app, [new_endpoint, :url, :scheme], "https")
|> Igniter.Project.Config.configure_runtime_env(
:prod,
otp_app,
[new_endpoint, :http, :ip],
{:code, Sourceror.parse_string!("{0, 0, 0, 0, 0, 0, 0, 0}")}
)
|> Igniter.Project.Config.configure("runtime.exs", otp_app, [new_endpoint, :http, :port], {:code, Sourceror.parse_string!("port")})
|> Igniter.Project.Config.configure("runtime.exs", otp_app, [new_endpoint, :secret_key_base], {:code, Sourceror.parse_string!("secret_key_base")})
|> Igniter.Project.Config.configure(
"runtime.exs",
|> Igniter.Project.Config.configure_runtime_env(:prod, otp_app, [new_endpoint, :http, :port], {:code, Sourceror.parse_string!("port")})
|> Igniter.Project.Config.configure_runtime_env(
:prod,
otp_app,
[new_endpoint, :secret_key_base],
{:code, Sourceror.parse_string!("secret_key_base")}
)
|> Igniter.Project.Config.configure_runtime_env(
:prod,
otp_app,
[proxy_endpoint, :check_origin],
[],
Expand Down
12 changes: 6 additions & 6 deletions test/mix/tasks/gen_proxy_endpoint.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ defmodule Mix.Tasks.Beacon.GenProxyEndpointTest do
project
|> Igniter.compose_task("beacon.gen.proxy_endpoint", signing_salt: "SNUXnTNM")
|> assert_has_patch("config/runtime.exs", """
3 + |config :test, TestWeb.ProxyEndpoint,
4 + | check_origin: [],
5 + | url: [port: 443, scheme: "https"],
6 + | http: [ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: port],
7 + | secret_key_base: secret_key_base
8 + |
53 + |config :test, TestWeb.ProxyEndpoint,
54 + | check_origin: [],
55 + | url: [port: 443, scheme: "https"],
56 + | http: [ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: port],
57 + | secret_key_base: secret_key_base
58 + |
""")
end
end
10 changes: 5 additions & 5 deletions test/mix/tasks/gen_site_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ defmodule Mix.Tasks.Beacon.GenSiteTest do
project
|> Igniter.compose_task("beacon.gen.site", @opts_my_site ++ ~w(--host example.com))
|> assert_has_patch("config/runtime.exs", """
3 + |config :test, TestWeb.ExampleEndpoint,
4 + | url: [host: "example.com", port: 443, scheme: "https"],
5 + | http: [ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: port],
6 + | secret_key_base: secret_key_base
7 + |
60 + |config :test, TestWeb.ExampleEndpoint,
61 + | url: [host: "example.com", port: 443, scheme: "https"],
62 + | http: [ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: port],
63 + | secret_key_base: secret_key_base
64 + |
""")
|> assert_has_patch("config/runtime.exs", """
8 + |config :test, TestWeb.ProxyEndpoint, check_origin: ["example.com"]
Expand Down

0 comments on commit 63cd932

Please sign in to comment.