diff options
-rw-r--r-- | src/ucs.ml | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -19,7 +19,7 @@ open Lwt open Cohttp open Cohttp_lwt_unix -let body = +let body () = let parameters = Uri.encoded_of_query ["start", ["2020-09-01"]; "end", ["2020-10-01"]; "resType", ["103"]; "calView", ["month"]; @@ -30,8 +30,19 @@ let body = >>= fun (_resp, body) -> Cohttp_lwt.Body.to_string body +let server = + let callback _conn req _body = + let meth = Request.meth req in + match meth with + | `GET -> + body () >>= fun body -> + let body = Ics.to_string @@ Course.decode body and + headers = Header.init_with "Content-Type" "text/calendar" in + Server.respond_string ~status:`OK ~body ~headers () + | _ -> + Server.respond_string + ~status:`Method_not_allowed ~body:"Method not allowed\n" () in + Server.create ~mode:(`TCP (`Port 8080)) (Server.make ~callback ()) + let () = - Lwt_main.run body - |> Course.decode - |> Ics.to_string - |> print_endline + ignore @@ Lwt_main.run server |