View Source Bandit.PhoenixAdapter (Bandit v1.0.0-pre.13)
A Bandit adapter for Phoenix.
This adapter provides out-of-the-box support for all aspects of Phoenix 1.7 and later. Earlier versions of Phoenix will work with this adapter, but without support for WebSockets.
To use this adapter, your project will need to include Bandit as a dependency:
{:bandit, "~> 1.0-pre"}
Once Bandit is included as a dependency of your Phoenix project, add the following adapter:
line to your endpoint configuration in config/config.exs
, as in the following example:
# config/config.exs
config :your_app, YourAppWeb.Endpoint,
adapter: Bandit.PhoenixAdapter, # <---- ADD THIS LINE
url: [host: "localhost"],
render_errors: ...
That's it! After restarting Phoenix you should see the startup message indicate that it is being served by Bandit, and everything should 'just work'. Note that if you have set any exotic configuration options within your endpoint, you may need to update that configuration to work with Bandit; see below for details.
Endpoint configuration
This adapter supports the standard Phoenix structure for endpoint configuration. Top-level keys for
:http
and :https
are supported, and configuration values within each of those are interpreted
as raw Bandit configuration as specified by Bandit.options/0
. Bandit's confguration supports
all values used in a standard out-of-the-box Phoenix application, so if you haven't made any
substantial changes to your endpoint configuration things should 'just work' for you.
In the event that you have made advanced changes to your endpoint configuration, you may need
to update this config to work with Bandit. Consult Bandit's documentation at
Bandit.options/0
for details.