wip: currently rewriting the project as a full stack application
tangled.org/kacaii.dev/sigo
gleam
1import gleam/erlang/process
2import gleam/http/request
3import gleam/http/response
4import gleam/otp/actor
5import gleam/otp/static_supervisor as supervisor
6import group_registry
7import mist
8import pog
9import wisp
10import wisp/wisp_mist
11
12/// Alias for a mist http request
13type Request =
14 request.Request(mist.Connection)
15
16/// Alias for a mist http response
17type Response =
18 response.Response(mist.ResponseData)
19
20/// Start the application supervisor
21pub fn start(
22 pog_config pog_config: pog.Config,
23 wisp_handler wisp_handler: fn(wisp.Request) -> wisp.Response,
24 ws_handler ws_handler: fn(Request) -> Response,
25 secret_key_base secret_key_base: String,
26 registry_name registry_name: process.Name(_),
27) -> Result(actor.Started(supervisor.Supervisor), actor.StartError) {
28 let handle_request = fn(req: Request) {
29 case wisp.path_segments(req) {
30 ["ws"] -> ws_handler(req)
31 _ -> wisp_mist.handler(wisp_handler, secret_key_base)(req)
32 }
33 }
34
35 let mist_builder =
36 handle_request
37 |> mist.new
38 |> mist.bind("0.0.0.0")
39 |> mist.port(8000)
40
41 // Starting supervision
42 supervisor.new(supervisor.OneForOne)
43 |> supervisor.add(pog.supervised(pog_config))
44 |> supervisor.add(mist.supervised(mist_builder))
45 |> supervisor.add(group_registry.supervised(registry_name))
46 |> supervisor.start
47}