View Source Bandit.PhoenixAdapter (Bandit v0.7.3)
A Bandit adapter for Phoenix.
WebSocket support requires a version of Phoenix with Plug upgrade support, which is available as part of Phoenix 1.7 and later. This module will work fine on earlier versions of Phoenix, just without WebSocket support.
To use this adapter, your project will need to include Bandit as a dependency; see
https://hex.pm/bandit for details on the currently supported version of Bandit to include. Once
Bandit is included as a dependency of your Phoenix project, add the following to your endpoint
configuration in config/config.exs
:
config :your_app, YourAppWeb.Endpoint,
adapter: Bandit.PhoenixAdapter
endpoint-configuration
Endpoint configuration
Configuring Bandit within your Phoenix app is done in largely the same way as configuration for
Cowboy works. For the most part, your existing configuration within your /config/*.exs
files
will work unchanged, although some of the more exotic options are different. Bandit supports the
following parameters within the :http
and :https
parameters:
:http
: the configuration for the HTTP server. Accepts the following options:port
: The port to run on. Defaults to 4000. Note that if a Unix domain socket is specified in theip
option, the value ofport
must be0
.ip
: The address to bind to. Can be specified as a 4-element tuple such as{127, 0, 0, 1}
for IPv4 addresses, an 8-element tuple for IPv6 addresses, or using{:local, path}
to bind to a Unix domain socket. Defaults to the Bandit default of{0, 0, 0, 0, 0, 0, 0, 0}
.transport_options
: Any valid value fromThousandIsland.Transports.TCP
http_1_options
: Any valid value from thehttp_1_options
section ofBandit
's config documentationhttp_2_options
: Any valid value from thehttp_2_options
section ofBandit
's config documentationwebsocket_options
: Any valid value from thewebsocket_options
section ofBandit
's config documentation
Defaults to
false
, which will cause Bandit to not start an HTTP server.:https
: the configuration for the HTTPS server. Accepts the following options:port
: The port to run on. Defaults to 4040. Note that if a Unix domain socket is specified in theip
option, the value ofport
must be0
.ip
: The address to bind to. Can be specified as a 4-element tuple such as{127, 0, 0, 1}
for IPv4 addresses, an 8-element tuple for IPv6 addresses, or using{:local, path}
to bind to a Unix domain socket. Defaults to the Bandit default of{0, 0, 0, 0, 0, 0, 0, 0}
.transport_options
: Any valid value fromThousandIsland.Transports.SSL
http_1_options
: Any valid value from thehttp_1_options
section ofBandit
's config documentationhttp_2_options
: Any valid value from thehttp_2_options
section ofBandit
's config documentationwebsocket_options
: Any valid value from thewebsocket_options
section ofBandit
's config documentation
Defaults to
false
, which will cause Bandit to not start an HTTPS server.