Project restructure for better login

Restructure project into client / server to support a "pure javascript" gleam
project to work before the having enough info to launch the server components.
This commit is contained in:
lettosprey 2026-03-30 23:49:20 +02:00
parent e6851255dc
commit 5663b61906
7 changed files with 198 additions and 76 deletions

View file

@ -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