diff options
-rw-r--r-- | ROUTER_CHANGES.md | 12 | ||||
-rw-r--r-- | bin/server.ml | 4 | ||||
-rw-r--r-- | dune | 6 | ||||
-rw-r--r-- | lib/router.ml | 4 |
4 files changed, 17 insertions, 9 deletions
diff --git a/ROUTER_CHANGES.md b/ROUTER_CHANGES.md index 5f7aab3..b82f687 100644 --- a/ROUTER_CHANGES.md +++ b/ROUTER_CHANGES.md @@ -16,4 +16,14 @@ - Patterns (`s`, `/`, `/?`, `int`, `str`, `wildcard`, `@-->`) make the routes very declarative, but the necessary type annotations can become verbose, especially when inferring the correct `route` versus `router` types. - Static file handling with `Body.sendfile` and `Body.to_string` is straightforward, though error paths currently propagate raw errors rather than returning HTTP error responses (which might be improved later). - The `dune` setup is standard, with a shared library and pages sub-library, plus `ppx_rapper_eio` for DB bindings. -- Overall, the code structure is clean and idiomatic, but the interaction of the routes DSL with OCaml’s type system can be a bit tricky when refining precise types.
\ No newline at end of file +- Overall, the code structure is clean and idiomatic, but the interaction of the routes DSL with OCaml’s type system can be a bit tricky when refining precise types. + +## Dune shenanigans +deleted this but might come in handy later + (rule + (target styles.css) + (deps + input.css + tailwind.sh) + (action + (bash "sh %{workspace_root}/tailwind.sh"))) diff --git a/bin/server.ml b/bin/server.ml index f5a8830..21cd225 100644 --- a/bin/server.ml +++ b/bin/server.ml @@ -12,7 +12,9 @@ let request_handler ~db_pool Server.{ request; _ } = match Lib.Router.match_route request.meth request.target with | Some handler -> (match handler db_pool request with - | Ok response -> response + | Ok response -> + Logs.info (fun d -> d "apparently ok %S\n" request.target); + response | Error err -> Logs.err (fun m -> m "Handler error: %a" Caqti_error.pp err); Response.create `Internal_server_error) @@ -1,6 +0,0 @@ -(rule - (target styles.css) - (deps - (glob_files_rec assets/*)) - (action - (bash "sh ~/code/ocaml/bs5/tailwind.sh"))) diff --git a/lib/router.ml b/lib/router.ml index a29a8bc..c3b4af2 100644 --- a/lib/router.ml +++ b/lib/router.ml @@ -27,6 +27,7 @@ let static (path : Parts.t) (_db : Handler.pool) (_req : Request.t) : (Response.t, Caqti_error.t) result = let pat = Parts.wildcard_match path in + Logs.info (fun d -> d "static path %S\n" pat); match Body.sendfile pat with | Error _ -> Ok (Response.create `Not_found) | Ok body -> @@ -56,7 +57,8 @@ let routes (* nil - end of path (no more segments) *) (* @--> - binds the route pattern to the handler function *) (* Handler.get_posts - the function that handles this route *) - (* ; `GET, (s "assets" / wildcard) @--> static *) + (* NOTE this took fucking forever lol *) + ; `GET, (s "assets" /? wildcard) @--> static ; `GET, (s "posts" / int /? nil) @--> Handler.get_post (* / int - captures an integer parameter (post ID) *) ; `GET, (s "comments" / int /? nil) @--> Handler.get_comment |