Working basic htmx page and endpoint, WIP static file serving and dune test running
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
(executable
|
||||
(public_name stack_picker)
|
||||
(name main)
|
||||
(libraries
|
||||
stack_picker
|
||||
eio_main
|
||||
caqti-eio.unix
|
||||
cohttp-eio
|
||||
tyxml
|
||||
fmt
|
||||
unix
|
||||
logs.fmt
|
||||
logs.threaded)
|
||||
(preprocess
|
||||
(pps tyxml-ppx)))
|
||||
(rule
|
||||
(alias deploy)
|
||||
(deps static)
|
||||
(action
|
||||
(chdir %{workspace_root}
|
||||
(run ./scripts/validate_html.ml ))))
|
||||
(rule
|
||||
(alias static)
|
||||
(action
|
||||
(chdir %{workspace_root}
|
||||
(copy static/* ./ ))))
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
open Tyxml
|
||||
open Stack_picker.Srv
|
||||
|
||||
(* let () = Eio_main.run @@ fun env -> *)
|
||||
(* let url = "sqlite3://stack.db" |> Uri.of_string in *)
|
||||
(* Caqti_eio_unix.with_connection ~stdenv:(env :> Caqti_eio.stdenv) url (Stack_picker.Db.test env#stdout) *)
|
||||
(* |> Caqti_eio.or_fail *)
|
||||
let () = Logs.set_reporter (Logs_fmt.reporter ())
|
||||
and () = Logs.Src.set_level Cohttp_eio.src (Some Debug)
|
||||
|
||||
let () =
|
||||
let port = ref 8080 in
|
||||
Arg.parse
|
||||
[ ("-p", Arg.Set_int port, " Listening port number(8080 by default)") ]
|
||||
ignore "An HTTP/1.1 server";
|
||||
Eio_main.run @@ fun env ->
|
||||
Eio.Switch.run @@ fun sw ->
|
||||
run ~env ~sw ~port:!port
|
||||
[
|
||||
get "/ping" (fun _req ->
|
||||
let num = 1 in
|
||||
let resp =
|
||||
Printf.sprintf "Hello this is the num: %d" num
|
||||
|> Eio.Flow.string_source
|
||||
in
|
||||
Stack_picker.Srv.respond ~body:resp ());
|
||||
get "/" (fun _ ->
|
||||
let%html html_doc =
|
||||
{|
|
||||
<html>
|
||||
<script src="https://unpkg.com/htmx.org@2.0.3"></script>
|
||||
<title>Ocaml</title>
|
||||
<body>
|
||||
<p>Hello from ocaml!</p>
|
||||
<button _hx-get="/shop" _hx-swap="outerHTML">Shop</button>
|
||||
</body>
|
||||
</html>|}
|
||||
in
|
||||
Stack_picker.Srv.respondHtmlDoc ~body:html_doc ());
|
||||
get "/shop" (fun _ ->
|
||||
let%html doc =
|
||||
{|
|
||||
<ol>
|
||||
<li>Bat</li>
|
||||
<li>Cat</li>
|
||||
<li>Doggie</li>
|
||||
</ol>
|
||||
|}
|
||||
in
|
||||
respondHtml ~body:doc ());
|
||||
]
|
||||
Reference in New Issue
Block a user