diff --git a/lib/phoenix/endpoint.ex b/lib/phoenix/endpoint.ex index 346a4d84a4..465420ac29 100644 --- a/lib/phoenix/endpoint.ex +++ b/lib/phoenix/endpoint.ex @@ -181,6 +181,8 @@ defmodule Phoenix.Endpoint do [another: {Mod, :fun, [arg1, arg2]}] + When `false`, watchers can be disabled. + * `:force_watchers` - when `true`, forces your watchers to start even when the `:server` option is set to `false`. diff --git a/lib/phoenix/endpoint/supervisor.ex b/lib/phoenix/endpoint/supervisor.ex index 253db8c9cb..5ee904dcb7 100644 --- a/lib/phoenix/endpoint/supervisor.ex +++ b/lib/phoenix/endpoint/supervisor.ex @@ -161,8 +161,10 @@ defmodule Phoenix.Endpoint.Supervisor do end defp watcher_children(_mod, conf, server?) do + watchers = conf[:watchers] || [] + if server? || conf[:force_watchers] do - Enum.map(conf[:watchers], &{Phoenix.Endpoint.Watcher, &1}) + Enum.map(watchers, &{Phoenix.Endpoint.Watcher, &1}) else [] end diff --git a/test/phoenix/endpoint/supervisor_test.exs b/test/phoenix/endpoint/supervisor_test.exs index ca2f028bb1..235c5c0be4 100644 --- a/test/phoenix/endpoint/supervisor_test.exs +++ b/test/phoenix/endpoint/supervisor_test.exs @@ -145,6 +145,16 @@ defmodule Phoenix.Endpoint.SupervisorTest do end) end + test "init/1 doesn't start watchers when `:server` config is true and `:watchers` is false" do + Application.put_env(:phoenix, WatchersEndpoint, server: true, watchers: false) + {:ok, {_, children}} = Supervisor.init({:phoenix, WatchersEndpoint, []}) + + refute Enum.any?(children, fn + %{start: {Phoenix.Endpoint.Watcher, :start_link, _config}} -> true + _ -> false + end) + end + test "init/1 doesn't start watchers when `:server` config is false" do Application.put_env(:phoenix, WatchersEndpoint, server: false, watchers: @watchers) {:ok, {_, children}} = Supervisor.init({:phoenix, WatchersEndpoint, []})