Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions installer/templates/phx_single/config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ config :<%= @app_name %>, <%= @endpoint_module %>,<%= if @inside_docker_env? do
# Bind to 0.0.0.0 to expose the server to the docker host machine.
# This makes make the service accessible from any network interface.
# Change to `ip: {127, 0, 0, 1}` to allow access only from the server machine.
http: [ip: {0, 0, 0, 0}, port: String.to_integer(System.get_env("PORT") || "4000")],<% else %>
http: [ip: {0, 0, 0, 0}],<% else %>
# Binding to loopback ipv4 address prevents access from other machines.
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
http: [ip: {127, 0, 0, 1}, port: String.to_integer(System.get_env("PORT") || "4000")],<% end %>
http: [ip: {127, 0, 0, 1}],<% end %>
check_origin: false,
code_reloader: true,
debug_errors: true,
Expand Down
7 changes: 4 additions & 3 deletions installer/templates/phx_single/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ if System.get_env("PHX_SERVER") do
config :<%= @app_name %>, <%= @endpoint_module %>, server: true
end

config :<%= @app_name %>, <%= @endpoint_module %>,
http: [port: String.to_integer(System.get_env("PORT", "4000"))]

if config_env() == :prod do
# The secret key base is used to sign/encrypt cookies and other secrets.
# A default value is used in config/dev.exs and config/test.exs but you
Expand All @@ -34,7 +37,6 @@ if config_env() == :prod do
"""

host = System.get_env("PHX_HOST") || "example.com"
port = String.to_integer(System.get_env("PORT") || "4000")

config :<%= @app_name %>, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")

Expand All @@ -45,8 +47,7 @@ if config_env() == :prod do
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
# See the documentation on <%= @web_adapter_docs %>
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
ip: {0, 0, 0, 0, 0, 0, 0, 0},
port: port
ip: {0, 0, 0, 0, 0, 0, 0, 0}
],
secret_key_base: secret_key_base

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ config :<%= @web_app_name %>, <%= @endpoint_module %>,<%= if @inside_docker_env?
# Bind to 0.0.0.0 to expose the server to the docker host machine.
# This makes make the service accessible from any network interface.
# Change to `ip: {127, 0, 0, 1}` to allow access only from the server machine.
http: [ip: {0, 0, 0, 0}, port: String.to_integer(System.get_env("PORT") || "4000")],<% else %>
http: [ip: {0, 0, 0, 0}],<% else %>
# Binding to loopback ipv4 address prevents access from other machines.
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
http: [ip: {127, 0, 0, 1}, port: String.to_integer(System.get_env("PORT") || "4000")],<% end %>
http: [ip: {127, 0, 0, 1}],<% end %>
check_origin: false,
code_reloader: true,
debug_errors: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ config :<%= @web_app_name %>, <%= @endpoint_module %>,
http: [
# Enable IPv6 and bind on all interfaces.
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
ip: {0, 0, 0, 0, 0, 0, 0, 0},
port: String.to_integer(System.get_env("PORT") || "4000")
ip: {0, 0, 0, 0, 0, 0, 0, 0}
],
secret_key_base: secret_key_base

Expand Down
4 changes: 4 additions & 0 deletions installer/templates/phx_umbrella/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import Config
# and secrets from environment variables or elsewhere. Do not define
# any compile-time configuration in here, as it won't be applied.
# The block below contains prod specific runtime configuration.

config :<%= @app_name %>, <%= @endpoint_module %>,
http: [port: String.to_integer(System.get_env("PORT", "4000"))]

if config_env() == :prod do
config :<%= @app_name %>, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
end
9 changes: 7 additions & 2 deletions installer/test/phx_new_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ defmodule Mix.Tasks.Phx.NewTest do
assert file =~ "config :logger, level: :info"
end)

assert_file("phx_blog/config/runtime.exs", ~r/ip: {0, 0, 0, 0, 0, 0, 0, 0}/)
assert_file("phx_blog/config/runtime.exs", fn file ->
assert file =~
~r/^ http: \[port: String.to_integer\(System.get_env\("PORT", "4000"\)\)\]$/m

assert file =~ ~r/^\s+ip: {0, 0, 0, 0, 0, 0, 0, 0}$/m
end)

assert_file("phx_blog/lib/phx_blog/application.ex", ~r/defmodule PhxBlog.Application do/)
assert_file("phx_blog/lib/phx_blog.ex", ~r/defmodule PhxBlog do/)
Expand Down Expand Up @@ -147,7 +152,7 @@ defmodule Mix.Tasks.Phx.NewTest do
assert file =~ "esbuild: {Esbuild,"
assert file =~ "lib/phx_blog_web/router\\.ex$"
assert file =~ "lib/phx_blog_web/(controllers|live|components)/.*\\.(ex|heex)$"
assert file =~ "http: [ip: {127, 0, 0, 1}"
assert file =~ "http: [ip: {127, 0, 0, 1}]"
end)

# tailwind
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/phx.gen.cert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ defmodule Mix.Tasks.Phx.Gen.Cert do
configuration in config/dev.exs:

config #{inspect(app)}, #{inspect(Mix.Phoenix.web_module(base))}.Endpoint,
http: [port: String.to_integer(System.get_env("PORT") || "4000")],
...,
https: [
port: 4001,
cipher_suite: :strong,
Expand Down