Gandalf is a protector plug that keeps away all unwanted visitors.
If available in Hex, the package can be installed
by adding gandalf
to your list of dependencies in mix.exs
:
def deps do
[{:gandalf, "~> 0.1.0"}]
end
Add plug to endpoint file before router:
Plug Gandalf
Plug YourApp.Router
Two ways to configure Gandalf:
- In
config/config.exs
(or any other env-config)
config :gandalf, auth_key: "auth_key_goes_here"
- When adding a plug inside endpoint file, provide auth_key param:
Plug Gandalf, auth_key: "auth_key_goes_here"
Paths:
To whitelist paths add whitelisted_paths: ~r/path1|path2/
to config.
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/gandalf.
Run plug application for development:
$ iex -S mix
iex> c "lib/gandalf.ex"
iex> {:ok, _} = Plug.Adapters.Cowboy.http Gandalf, %{auth_key: "1234"}
Access http://localhost:4000