diff options
author | polwex <polwex@sortug.com> | 2025-07-16 15:36:16 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-07-16 15:36:16 +0700 |
commit | 7acccc847e58ba5c04561890783bcd852df7e40b (patch) | |
tree | 896be9364df38fb4e4e96f08354f882ef947e69a /lib/router.ml | |
parent | 5bd56c54095a772cf14aae82389bf104338d7ac8 (diff) |
m
Diffstat (limited to 'lib/router.ml')
-rw-r--r-- | lib/router.ml | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/router.ml b/lib/router.ml index 8649e5f..03e11f3 100644 --- a/lib/router.ml +++ b/lib/router.ml @@ -23,6 +23,20 @@ module R = Map.Make (struct ;; end) +let static path _db _req = + let pat = Parts.wildcard_match path in + match Body.sendfile pat with + | Error err -> Error err + | Ok body -> + (match Body.to_string body with + | Error e -> Error e + | Ok str -> Ok (Response.of_string ~body:str Status.(`Accepted))) +;; + +(* match Parts.wildcard_match path with *) +(* | "styles.css" -> Ok (Response.of_string ~body:"" Status.(`Accepted)) *) +(* | _ -> Ok (Response.of_string ~body:"" Status.(`Accepted)) *) + (* Define all routes in the application *) let routes = (* Use fold_left to build up a map of routes *) @@ -38,6 +52,7 @@ 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 *) ; `GET, (s "posts" / int /? nil) @--> Handler.get_post (* / int - captures an integer parameter (post ID) *) ; `GET, (s "comments" / int /? nil) @--> Handler.get_comment |