View Source Unplug (Unplug v1.1.0)
The purpose of Unplug
is to provide a wrapper around any arbitrary plug,
with the ability to conditionally execute that plug at run-time. The runtime
conditions that are leveraged by Unplug
must conform to the Unplug.Predicate
behaviour. Out of the box Unplug
comes with predicates that can be used to
execute plugs based on:
- Environment variable values
- Application config values
- Request header values
- Request path values
Unplug
also preserves the behavior of Plug
in that in its init/1
function
it will evaluate the init/1
functions of your conditional plugs and store their
values so that the call/2
function does not have to reevaluate the init/1
functions of your conditional plugs every time the plug pipeline is invoked (see
the Plug
docs for more information https://hexdocs.pm/plug/Plug.Builder.html#module-options).
To use Unplug
, add an entry in your endpoint.ex
or router.ex
files like
so:
plug Unplug,
if: {Unplug.Predicates.RequestPathIn, ["/metrics", "healthcheck"]}
do: {Plug.Telemetry, event_prefix: [:phoenix, :endpoint]}