ton of refactoring, dropped lustre for a wasm frontend in rust

This commit is contained in:
2025-05-07 19:38:31 -06:00
parent 76522cc053
commit 91547b9c2e
18 changed files with 543 additions and 224 deletions
+71 -2
View File
@@ -1,5 +1,74 @@
import gleam/io
import app/router
import app/web
import argv
import config
import gleam/erlang/process
import gleam/result
import glint
import mist
import session
import storail
pub type Error {
ConfigError(config.ConfigError)
}
pub fn error_string(err: Error) -> String {
case err {
ConfigError(err) -> config.error_to_string(err)
}
}
pub fn setup_session_collection(
config: storail.Config,
) -> storail.Collection(session.Session) {
storail.Collection(
name: "Sessions",
to_json: session.serialize,
decoder: session.decoder(),
config:,
)
}
pub fn run_server() -> glint.Command(Result(Nil, Error)) {
use <- glint.command_help("Runs the backend of Play of the Game")
use _, args, _ <- glint.command()
let cfg_path = case args {
[] -> "config.toml"
[cfg_path, ..] -> cfg_path
}
use cfg <- result.try(
result.map_error(config.from_file(cfg_path), fn(err) {
let err = ConfigError(err)
err
}),
)
let storail_cfg = storail.Config(cfg.storage_path)
let ctx =
web.Context(config: cfg, sessions: setup_session_collection(storail_cfg))
let handler = router.handle_request(_, ctx)
let assert Ok(_) =
handler
|> mist.new
|> mist.bind(cfg.host)
|> mist.port(cfg.port)
|> mist.start_http
process.sleep_forever()
Ok(Nil)
}
pub fn main() {
io.println("Hello from backend!")
glint.new()
|> glint.with_name("Play Of The Game")
|> glint.pretty_help(glint.default_pretty_help())
|> glint.add(at: [], do: run_server())
|> glint.run(argv.load().arguments)
}