Packages

Small plug to toggle routes based on their patch by a environment variable or app config

Current section

Files

Jump to
route_toggle_plug lib route_toggle_plug.ex
Raw

lib/route_toggle_plug.ex

defmodule RouteTogglePlug do
import Plug.Conn
def init(opts) do
opts
end
def call(conn = %{request_path: path}, paths: paths, key: key) do
if path not in paths || Application.get_env(:route_toggle_plug, key) do
conn
else
conn
|> Plug.Conn.resp(404, "Not found")
|> halt
end
end
def call(conn, _opts) do
conn
end
end