From 2089e77e4c6e21166e855df1966d722de70da9b7 Mon Sep 17 00:00:00 2001 From: "kacaii.dev" Date: Wed, 26 Aug 2026 18:41:50 -0300 Subject: [PATCH] router: send html to the client when accessing root --- gleam.toml | 1 + manifest.toml | 2 ++ src/server/router.gleam | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gleam.toml b/gleam.toml index 720ab34..c1d9e10 100644 --- a/gleam.toml +++ b/gleam.toml @@ -24,6 +24,7 @@ mist = ">= 6.0.3 and < 7.0.0" wisp = ">= 2.2.2 and < 3.0.0" filepath = ">= 1.1.2 and < 2.0.0" global_value = ">= 1.0.0 and < 2.0.0" +lustre = ">= 5.7.1 and < 6.0.0" [dev_dependencies] gleeunit = ">= 1.0.0 and < 2.0.0" diff --git a/manifest.toml b/manifest.toml index d3b4d8f..8e17d8d 100644 --- a/manifest.toml +++ b/manifest.toml @@ -34,6 +34,7 @@ packages = [ { name = "hpack_erl", version = "0.3.0", build_tools = ["rebar3"], requirements = [], otp_app = "hpack", source = "hex", outer_checksum = "D6137D7079169D8C485C6962DFE261AF5B9EF60FBC557344511C1E65E3D95FB0" }, { name = "justin", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "justin", source = "hex", outer_checksum = "8B1C62269E8607D0A0ED698B7903984CE0BF7B6B3C0DEA3C6C8302B39402837B" }, { name = "logging", version = "1.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "logging", source = "hex", outer_checksum = "BC5F18CE5DD9686100229FE5409BDC3DD5C46D5A7DF2F804AD2D8F0DD6C5060E" }, + { name = "lustre", version = "5.7.1", build_tools = ["gleam"], requirements = ["exception", "gleam_erlang", "gleam_json", "gleam_otp", "gleam_stdlib", "houdini"], otp_app = "lustre", source = "hex", outer_checksum = "663A2D1A3458914CA537A42AC07E601DD3FD85415EBDAF4717F2DFF6E86F90F9" }, { name = "marceau", version = "1.3.0", build_tools = ["gleam"], requirements = [], otp_app = "marceau", source = "hex", outer_checksum = "2D1C27504BEF45005F5DFB18591F8610FB4BFA91744878210BDC464412EC44E9" }, { name = "mist", version = "6.0.3", build_tools = ["gleam"], requirements = ["exception", "gleam_erlang", "gleam_http", "gleam_otp", "gleam_stdlib", "glisten", "gramps", "hpack_erl", "logging"], otp_app = "mist", source = "hex", outer_checksum = "1B07F321D5FA0CB162D81496F2DE96AEB6EF8980F4F38230A4CC3F849497E020" }, { name = "mug", version = "3.1.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "mug", source = "hex", outer_checksum = "C01279D98E40371DA23461774B63F0E3581B8F1396049D881B0C7EB32799D93F" }, @@ -62,6 +63,7 @@ gleam_otp = { version = ">= 1.3.0 and < 2.0.0" } gleam_stdlib = { version = ">= 1.0.0 and < 2.0.0" } gleeunit = { version = ">= 1.0.0 and < 2.0.0" } global_value = { version = ">= 1.0.0 and < 2.0.0" } +lustre = { version = ">= 5.7.1 and < 6.0.0" } mist = { version = ">= 6.0.3 and < 7.0.0" } pog = { version = ">= 4.1.0 and < 5.0.0" } squirrel = { version = ">= 4.7.0 and < 5.0.0" } diff --git a/src/server/router.gleam b/src/server/router.gleam index 40173fd..a3acb40 100644 --- a/src/server/router.gleam +++ b/src/server/router.gleam @@ -1,6 +1,9 @@ import gleam/http import gleam/http/request import gleam/http/response +import lustre/attribute +import lustre/element +import lustre/element/html import server/context import wisp @@ -9,9 +12,8 @@ pub fn handle_request( context: context.Context, ) -> response.Response(wisp.Body) { use request <- middleware(request, context) - case request.method, request.path_segments(request) { - http.Get, [] -> wisp.ok() + http.Get, [] -> html_document() // healthcheck http.Get, ["api", "healthcheck"] -> wisp.ok() @@ -35,3 +37,14 @@ fn middleware( next(request) } + +fn html_document() -> response.Response(wisp.Body) { + let body = + html.html([], [ + html.head([], [html.title([], "SENAC")]), + html.body([], [html.div([attribute.id("app")], [])]), + ]) + + element.to_document_string(body) + |> wisp.html_body(wisp.ok(), _) +} -- 2.51.2