-
-
Save andreypopp/8568c29b3addf98a4a70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Printf | |
open Lwt | |
open Cohttp | |
open Cohttp_lwt_unix | |
let make_server () = | |
let callback conn_id ?body req = | |
match Request.path req with | |
| "" | "/" -> | |
Server.respond_string ~status:`OK ~body:"helloworld" () | |
| "/post" -> begin | |
lwt body = Body.string_of_body body in | |
Server.respond_string ~status:`OK ~body () | |
end | |
| "/postnodrain" -> | |
Server.respond_string ~status:`OK ~body:"nodrain" () | |
| _ -> | |
let fname = Server.resolve_file ~docroot:"." ~uri:(Request.uri req) in | |
Server.respond_file ~fname () | |
in | |
let conn_closed conn_id () = | |
Printf.eprintf "conn %s closed\n%!" (Server.string_of_conn_id conn_id) | |
in | |
let config = { Server.callback; conn_closed } in | |
server ~address:"0.0.0.0" ~port:8081 config | |
let _ = Lwt_unix.run (make_server ()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment