From f0142aa1c3b4d7c2fd0b70c9e62c1ec033e445c2 Mon Sep 17 00:00:00 2001 From: Mateus Cruz Date: Mon, 5 Feb 2024 00:14:45 -0300 Subject: add basic route handling --- bin/dune | 4 ++-- bin/main.ml | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'bin') diff --git a/bin/dune b/bin/dune index 0716639..a186150 100644 --- a/bin/dune +++ b/bin/dune @@ -1,10 +1,10 @@ (executable - (public_name rinhadebackend) + (public_name rinha) (name main) (flags (:standard -cclib -static -cclib -no-pie)) (libraries - rinhadebackend + rinha piaf routes diff --git a/bin/main.ml b/bin/main.ml index 7bf6048..7e537a7 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1 +1,26 @@ -let () = print_endline "Hello, World!" +[@@@warning "-26-27-32"] + +open! StdLabels +open Eio +open Piaf + +let request_handler Server.{ request; _ } = + match Rinha.Router.match_route request.meth request.target with + | Some handler -> handler request + | None -> Response.create `Not_found +;; + +let () = + Eio_main.run + @@ fun env -> + Switch.run + @@ fun sw -> + let config = + let interface = Net.Ipaddr.V4.any in + let port = 3000 in + `Tcp (interface, port) + in + let config = Server.Config.create config in + let server = Server.create ~config request_handler in + ignore @@ Server.Command.start ~sw env server +;; -- cgit v1.2.3