defmodule Phoenix.CodeReloader do @moduledoc """ A plug and module to handle automatic code reloading. For each request, Phoenix checks if any of the modules previously compiled requires recompilation via `__phoenix_recompile__?/0` and then calls `mix compile` for sources exclusive to the `web` directory. To avoid race conditions, all code reloads are funneled through a sequential call operation. """ ## Server delegation @doc """ Reloads code within the paths specified in the `:reloadable_paths` config for the endpoint. This is configured in your application environment like: config :your_app, YourApp.Endpoint, reloadable_paths: ["web"] Keep in mind that the paths passed to :reloadable_paths must be a subset of the paths specified in the :elixirc_paths option of `project/0` in mix.exs. """ @spec reload!(module) :: :ok | :noop | {:error, binary()} defdelegate reload!(endpoint), to: Phoenix.CodeReloader.Server ## Plug @behaviour Plug import Plug.Conn @doc """ API used by Plug to start the code reloader. """ def init(opts), do: Keyword.put_new(opts, :reloader, &Phoenix.CodeReloader.reload!/1) @doc """ API used by Plug to invoke the code reloader on every request. """ def call(conn, opts) do case opts[:reloader].(conn.private.phoenix_endpoint) do {:error, output} -> conn |> put_resp_content_type("text/html") |> send_resp(500, template(conn, output)) |> halt() _ -> conn end end defp template(conn, output) do """
Showing console output
#{String.strip(output)}