basic static files w/ crunch

This commit is contained in:
Swrup 2025-09-13 19:32:30 +02:00
parent abec80c2e1
commit b96c671e01
5 changed files with 37 additions and 8 deletions

6
src/config.ml Normal file
View file

@ -0,0 +1,6 @@
(* https://docs.taler.net/manpages/taler-exchange.conf.5.html *)
let terms_dir = Fpath.(v "terms")
let terms_etag = "0"
let privacy_dir = Fpath.(v "privacy")
let privacy_etag = "0"

View file

@ -1,4 +1,14 @@
(executable
(public_name mte)
(name mte)
(modules assets mte config)
(libraries vif fmt jsont))
(rule
(target assets.ml)
(deps
(source_tree assets))
(action
(with-stdout-to
%{null}
(run ocaml-crunch -m plain assets -o %{target}))))

View file

@ -1,18 +1,31 @@
let terms req _server _env =
Vif.Response.with_file ~compression:`DEFLATE req
Fpath.(v "assets" / "terms.html")
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
let privacy req _server _env =
Vif.Response.with_file ~compression:`DEFLATE req
Fpath.(v "assets" / "privacy.html")
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
let static data req _server _env =
let open Vif.Response.Syntax in
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
let routes =
let open Vif.Uri in
let open Vif.Route in
(*let open Vif.Type in*)
[
get (rel / "terms" /?? nil) --> terms
; get (rel / "privacy" /?? nil) --> privacy
get (rel / "terms" /?? nil) --> static Assets.terms
; get (rel / "privacy" /?? nil) --> static Assets.privacy
]
let () =