mte/src/mte.ml

55 lines
1.3 KiB
OCaml
Raw Normal View History

2025-09-13 19:32:30 +02:00
module Assets = struct
let get path =
let path = Fpath.to_string path in
match Assets.read path with
| None -> Fmt.failwith "asset loading failure `%s`" path
| Some data -> data
2025-09-13 15:56:19 +02:00
2025-09-13 19:32:30 +02:00
let terms =
get Fpath.((Config.terms_dir / "en" / Config.terms_etag) + ".html")
let privacy =
get Fpath.((Config.privacy_dir / "en" / Config.privacy_etag) + ".html")
end
2025-09-14 23:04:53 +02:00
let static kind req _server _env =
2025-09-13 19:32:30 +02:00
let open Vif.Response.Syntax in
2025-09-14 23:04:53 +02:00
let extension = .. in
if not @@ extension is supported then
error mimetype not supported
else
let base_dir, etag =
let open Config in
match kind with
| `Terms -> terms_dir, terms_etag
| `Privacy -> privacy_dir, privacy_etag
in
let accepted_lang_l = .. in
(* add headers ... *)
2025-09-13 19:32:30 +02:00
let* () = Vif.Response.with_string ~compression:`Gzip req data in
let field = "content-type" in
let* () = Vif.Response.add ~field "html; charset=utf-8" in
Vif.Response.respond `OK
2025-09-13 15:56:19 +02:00
let routes =
let open Vif.Uri in
let open Vif.Route in
(*let open Vif.Type in*)
[
2025-09-13 19:32:30 +02:00
get (rel / "terms" /?? nil) --> static Assets.terms
; get (rel / "privacy" /?? nil) --> static Assets.privacy
2025-09-13 15:56:19 +02:00
]
2025-09-13 17:57:29 +02:00
let () =
Miou_unix.run @@ fun () ->
let env = () in
let middlewares = Vif.Middlewares.[] in
Vif.run ~middlewares routes env