Plug.Adapters.Cowboy

Adapter interface to the Cowboy webserver.

Options

Summary

child_spec(scheme, plug, opts, options \\ [])

Returns a child spec to be supervised by your application

http(plug, opts, options \\ [])

Run cowboy under http

https(plug, opts, options \\ [])

Run cowboy under https

shutdown(ref)

Shutdowns the given reference

Functions

child_spec(scheme, plug, opts, options \\ [])

Returns a child spec to be supervised by your application.

http(plug, opts, options \\ [])

Specs:

  • http(module, Keyword.t, Keyword.t) :: {:ok, pid} | {:error, :eaddrinuse} | {:error, term}

Run cowboy under http.

Example

# Starts a new interface
Plug.Adapters.Cowboy.http MyPlug, [], port: 80

# The interface above can be shutdown with
Plug.Adapters.Cowboy.shutdown MyPlug.HTTP
https(plug, opts, options \\ [])

Specs:

  • https(module, Keyword.t, Keyword.t) :: {:ok, pid} | {:error, :eaddrinuse} | {:error, term}

Run cowboy under https.

Besides the options described in the module documentation, this module also accepts all options defined in [the `ssl` erlang module] (http://www.erlang.org/doc/man/ssl.html), like keyfile, certfile, cacertfile and others.

The certificate files can be given as a relative path. For such, the :otp_app option must also be given and certificates will be looked from the priv directory of the given application.

Example

# Starts a new interface
Plug.Adapters.Cowboy.https MyPlug, [],
  port: 443,
  password: "SECRET",
  otp_app: :my_app,
  keyfile: "ssl/key.pem",
  certfile: "ssl/cert.pem"

# The interface above can be shutdown with
Plug.Adapters.Cowboy.shutdown MyPlug.HTTPS
shutdown(ref)

Shutdowns the given reference.