diff options
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 |