Packages

Adds live-reload functionality to Plug for development.

Current section

Files

Jump to
plug_live_reload lib plug_live_reload application.ex
Raw

lib/plug_live_reload/application.ex

defmodule PlugLiveReload.Application do
@moduledoc false
use Application
require Logger
def start(_type, _args) do
children = [%{id: __MODULE__, start: {__MODULE__, :start_link, []}}]
Supervisor.start_link(children, strategy: :one_for_one)
end
def start_link do
dirs = Application.get_env(:plug_live_reload, :dirs, [""])
backend_opts = Application.get_env(:plug_live_reload, :backend_opts, [])
opts =
[
name: :plug_live_reload_file_monitor,
dirs: Enum.map(dirs, &Path.absname/1)
] ++ backend_opts
opts =
if backend = Application.get_env(:plug_live_reload, :backend) do
[backend: backend] ++ opts
else
opts
end
case FileSystem.start_link(opts) do
{:ok, pid} ->
{:ok, pid}
other ->
Logger.warning("""
Could not start Plug live-reload because we cannot listen to the file system.
You don't need to worry! This is an optional feature used during development to
refresh your browser when you save files and it does not affect production.
""")
other
end
end
end