March Docs

BastionServer

BastionServer — convenience wrappers for starting a Bastion HTTP server.

Usage:

fn main() do
  let router = build_router()
  BastionServer.start(router, Bastion.default_opts(4000))
end

Functions

fnspawn_nspawn_n(router : Router, opts : Opts, n : Int) : Int#

Start the server in a subprocess that handles exactly n requests, then exits. Returns an integer handle that can be passed to BastionServer.wait_for/1. Useful for integration tests — lets the test drive request count.

fnstartstart(router : Router, opts : Opts) : Unit#

Start the Bastion server with the given router and options.

Converts the Router into an HttpServer plug and calls HttpServer.listen/1.
Blocks the calling process until the server exits.

Example:
  BastionServer.start(router, Bastion.default_opts(4000))
fnstart_plugstart_plug(plug : Conn -> Conn, opts : Opts) : Unit#

Start the Bastion server with a pre-built plug and options. Use this when you need to wrap the router in middleware (logger, static-file, etc.) before serving — the plug you supply is the single handler that every request flows through.

Example:
  let pipeline = fn conn ->
    Middleware.pipeline([Middleware.logger, static_plug, Router.to_plug(router)], conn)
  BastionServer.start_plug(pipeline, Bastion.default_opts(4000))
fnwait_forwait_for(handle : Int) : Unit#

Wait for a server subprocess returned by spawn_n to exit.