Fixes to routing and new build for Dockerfile
This commit is contained in:
parent
0024687621
commit
ccdba0f239
4 changed files with 97 additions and 47 deletions
|
|
@ -4,13 +4,14 @@ import backend/statehandler
|
|||
import gleam/bytes_tree
|
||||
import gleam/erlang/application
|
||||
import gleam/erlang/process
|
||||
import gleam/http
|
||||
import gleam/http/request
|
||||
import gleam/http/response.{type Response}
|
||||
import gleam/list
|
||||
import gleam/option.{None}
|
||||
import gleam/result
|
||||
import gleam/string
|
||||
import mist.{type ResponseData, File}
|
||||
import mist.{type ResponseData}
|
||||
import web/components/answerlist
|
||||
import web/components/card
|
||||
import web/components/control
|
||||
|
|
@ -25,29 +26,36 @@ pub fn main() {
|
|||
let assert Ok(room_handler) = roomhandler.initialize(state_handler)
|
||||
|
||||
let assert Ok(_) =
|
||||
fn(req) {
|
||||
case request.path_segments(req) {
|
||||
["lustre", "runtime.mjs"] -> serve_runtime()
|
||||
[] | ["index.html"]-> serve_static("root.html")
|
||||
["client.js"] -> serve_static("client.js")
|
||||
["static", file] -> serve_static(file)
|
||||
["socket", "card", id] ->
|
||||
sockethandler.serve(req, card.component(), id, room_handler)
|
||||
["socket", "control", id] ->
|
||||
sockethandler.serve(req, control.component(), id, room_handler)
|
||||
["socket", "slow", id] ->
|
||||
sockethandler.serve_slow(
|
||||
req,
|
||||
answerlist.component(),
|
||||
id,
|
||||
room_handler,
|
||||
state_handler,
|
||||
)
|
||||
fn(req: request.Request(mist.Connection)) {
|
||||
case req.method {
|
||||
// Filter out Head requests,
|
||||
http.Head ->
|
||||
response.new(200)
|
||||
|> response.set_body(mist.Bytes(bytes_tree.new()))
|
||||
_ ->
|
||||
wisp_mist.handler(
|
||||
router.handle_request(room_handler, state_handler, _),
|
||||
"very_secret",
|
||||
)(req)
|
||||
case request.path_segments(req) {
|
||||
["lustre", "runtime.mjs"] -> serve_runtime()
|
||||
[] | ["index.html"] -> serve_static("root.html")
|
||||
["client.js"] -> serve_static("client.js")
|
||||
["static", file] -> serve_static(file)
|
||||
["socket", "card", id] ->
|
||||
sockethandler.serve(req, card.component(), id, room_handler)
|
||||
["socket", "control", id] ->
|
||||
sockethandler.serve(req, control.component(), id, room_handler)
|
||||
["socket", "slow", id] ->
|
||||
sockethandler.serve_slow(
|
||||
req,
|
||||
answerlist.component(),
|
||||
id,
|
||||
room_handler,
|
||||
state_handler,
|
||||
)
|
||||
_ ->
|
||||
wisp_mist.handler(
|
||||
router.handle_request(room_handler, state_handler, _),
|
||||
"very_secret",
|
||||
)(req)
|
||||
}
|
||||
}
|
||||
}
|
||||
|> mist.new
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue