Skip to content

Commit

Permalink
Adding info log if they have http/https set but not server: true set (#…
Browse files Browse the repository at this point in the history
…5362)

* Adding info log if they have http/https set but not server: true set

---------

Co-authored-by: José Valim <jose.valim@dashbit.co>
  • Loading branch information
jeregrine and josevalim committed Mar 20, 2023
1 parent 68c0096 commit c44ea28
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
19 changes: 14 additions & 5 deletions lib/phoenix/endpoint/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,20 @@ defmodule Phoenix.Endpoint.Supervisor do
end

defp server_children(mod, config, server?) do
if server? do
adapter = config[:adapter] || Phoenix.Endpoint.Cowboy2Adapter
adapter.child_specs(mod, config)
else
[]
cond do
server? ->
adapter = config[:adapter] || Phoenix.Endpoint.Cowboy2Adapter
adapter.child_specs(mod, config)

config[:http] || config[:https] ->
Logger.info(
"Configuration :server was not enabled for #{inspect(mod)}, http/https services won't start"
)

[]

true ->
[]
end
end

Expand Down
39 changes: 38 additions & 1 deletion test/phoenix/endpoint/supervisor_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Phoenix.Endpoint.SupervisorTest do
use ExUnit.Case, async: true
use ExUnit.Case, async: false
alias Phoenix.Endpoint.Supervisor

defmodule HTTPSEndpoint do
Expand Down Expand Up @@ -40,6 +40,11 @@ defmodule Phoenix.Endpoint.SupervisorTest do
def config(:static_url), do: [host: "static.example.com"]
end

defmodule ServerEndpoint do
def init(:supervisor, config), do: {:ok, config}
def __sockets__(), do: []
end

setup_all do
Application.put_env(:phoenix, SupervisorApp.Endpoint, custom: true)
System.put_env("PHOENIX_PORT", "8080")
Expand Down Expand Up @@ -85,6 +90,38 @@ defmodule Phoenix.Endpoint.SupervisorTest do
Supervisor.static_lookup(HTTPEndpoint, "/images/unknown.png")
end

import ExUnit.CaptureLog
test "logs info if :http or :https configuration is set but not :server" do
Logger.configure(level: :info)
Application.put_env(:phoenix, ServerEndpoint, [server: false, http: [], https: []])
assert capture_log(fn ->
{:ok, {_, _children}} = Supervisor.init({:phoenix, ServerEndpoint, []})
end) =~ "Configuration :server"

Application.put_env(:phoenix, ServerEndpoint, [server: false, http: []])
assert capture_log(fn ->
{:ok, {_, _children}} = Supervisor.init({:phoenix, ServerEndpoint, []})
end) =~ "Configuration :server"

Application.put_env(:phoenix, ServerEndpoint, [server: false, https: []])
assert capture_log(fn ->
{:ok, {_, _children}} = Supervisor.init({:phoenix, ServerEndpoint, []})
end) =~ "Configuration :server"

Application.put_env(:phoenix, ServerEndpoint, [server: false])
refute capture_log(fn ->
{:ok, {_, _children}} = Supervisor.init({:phoenix, ServerEndpoint, []})
end) =~ "Configuration :server"

Application.put_env(:phoenix, ServerEndpoint, [server: true])
refute capture_log(fn ->
{:ok, {_, _children}} = Supervisor.init({:phoenix, ServerEndpoint, []})
end) =~ "Configuration :server"

Application.delete_env(:phoenix, ServerEndpoint)
Logger.configure(level: :warning)
end

describe "watchers" do
defmodule WatchersEndpoint do
def init(:supervisor, config), do: {:ok, config}
Expand Down

0 comments on commit c44ea28

Please sign in to comment.