From 2f18b8a33cabd0ea666781ba048d0174b4dc5031 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sun, 1 Jun 2025 17:12:06 +0200 Subject: Initial commit --- bin/main.ml | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 bin/main.ml (limited to 'bin/main.ml') diff --git a/bin/main.ml b/bin/main.ml new file mode 100644 index 0000000..f1f0cfd --- /dev/null +++ b/bin/main.ml @@ -0,0 +1,58 @@ +(** Create the handler for the service *) +let handler = + Dream_handler.handle + (module Services_impl.Nb_car) + (fun (() : Services_impl.Nb_car.placeholders) body -> + Lwt.return_ok + Services_impl.Nb_car. + { + value = body.value; + nbcar = Int64.of_int (String.length body.value); + }) + +(* The handler and the route are not created at the same time because we may + want create a specific handler, for example one checking CRSF in the query + and can’t infer this from the service signature only *) + +(** And create the route. *) +let route = Dream_handler.register (module Services_impl.Nb_car) handler + +(** Generate a default static page *) +let hello : Dream.handler = + fun _ -> + Dream.html + {| + +

Hello!

+
+ + + +
+
+ +|} + +let js_assets _root path _request = + (* This module is automatically generated — see the dune file to see the rule *) + match JsAssets.read path with + | None -> Dream.empty `Not_Found + | Some asset -> Dream.respond asset + +let () = + Dream.run @@ Dream.logger + @@ Dream.router + [ + Dream.get "/js/**" (Dream.static ~loader:js_assets ""); + Dream.get "/" hello; + route; + ] + +(* Now test the application by connecting to + http://localhost:8080/ + *) -- cgit v1.2.3