messua

Types

The type we use for building a server configuration.

pub opaque type Config(state)

Values

pub fn default() -> Config(Nil)

Default server configuration.

Listens on “localhost:8080”, state is Nil. Use the other builder-pattern functions in this module to change the defaults.

pub fn start(
  config: Config(state),
  handler: fn(minc.Incoming(state)) -> Result(
    response.Response(mist.ResponseData),
    fail.Failure,
  ),
) -> Nil

Start the server with the given handler.

This function doesn’t return (but may panic), blocking the current thread (or Erlang process or whatever).

If you have configured your server without either HTTP or HTTPS, this will definitely panic and let you know.

pub fn with_binding(
  config: Config(state),
  addr_str: String,
) -> Config(state)

Configure the server to use a different binding.

This should be a string that can be parsed as a network address, like "0.0.0.0" or "localhost" (which is the default). An invalid value here will cause a panic when the server starts.

pub fn with_http_port(
  config: Config(state),
  port: Int,
) -> Config(state)

Configure the server to use a different HTTP port.

pub fn with_state(
  config: Config(t),
  state: state,
) -> Config(state)

Configure the server with the given state object. This mutable state will be handled in a concurrency-safe way and available through the Incoming(state) argument to your handler function.

pub fn with_state_timeout(
  config: Config(state),
  ms: Int,
) -> Config(state)

Set the timeout value for access to server state in request handlers to ms milliseconds.

The default timeout is 5000 ms.

NB: Read-only access won’t time out, but updating might.

pub fn with_tls(
  config: Config(state),
  cert_path: String,
  key_path: String,
  port: Int,
) -> Config(state)

Configure the server to listen with the given HTTPS configuration.

pub fn without_http(config: Config(state)) -> Config(state)

Do not listen for insecure requests.

Search Document