Skip to content
Open
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(lang dune 2.7)
(lang dune 3.21)
2 changes: 1 addition & 1 deletion example/4-counter/counter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ let () =
@@ count_requests
@@ Dream.router [
Dream.get "/" (fun _ ->
Dream.html (Printf.sprintf "Saw %i request(s)!" !count));
Dream.html (Printf.sprintf "Responding to the %i. request!" !count));
]
4 changes: 3 additions & 1 deletion src/dream.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2124,7 +2124,9 @@ val run :

- [~interface] is the network interface to listen on. Defaults to
["localhost"]. Use ["0.0.0.0"] to listen on all interfaces.
- [~port] is the port to listen on. Defaults to [8080].
- [~port] is the port to listen on. Defaults to [8080], or the value of the
environment variable [DREAM_PORT], if set. [~port] takes precedence over
[DREAM_PORT].
- If [~socket_path] is specified, Dream will listen on a Unix domain socket
at the given path, and ignore [~interface] and [~port].
- [~stop] is a promise that causes the server to stop accepting new
Expand Down
12 changes: 10 additions & 2 deletions src/http/http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -687,14 +687,20 @@ let on_termination_signal () =
ignore (Lwt_unix.on_signal Sys.sigint (fun _ -> Lwt.wakeup_later int_resolve ()));
Lwt.pick [term_promise; int_promise]

let get_port ?port () =
match port with
| Some p -> p
| None ->
(try int_of_string (Sys.getenv "DREAM_PORT") with Not_found -> default_port)

let network ~port ~socket_path =
match socket_path with
| None -> `Inet port
| Some path -> `Unix path

let serve
?(interface = default_interface)
?(port = default_port)
?port
?socket_path
?stop
?(error_handler = Error_handler.default)
Expand All @@ -704,6 +710,7 @@ let serve
?(builtins = true)
user's_dream_handler =

let port = get_port ?port () in
serve_with_maybe_https
"serve"
~interface
Expand All @@ -722,7 +729,7 @@ let serve

let run
?(interface = default_interface)
?(port = default_port)
?port
?socket_path
?stop
?(error_handler = Error_handler.default)
Expand All @@ -734,6 +741,7 @@ let run
?adjust_terminal
user's_dream_handler =

let port = get_port ?port () in
let () = if Sys.unix then
Sys.(set_signal sigpipe Signal_ignore)
in
Expand Down
3 changes: 3 additions & 0 deletions test/cram/1-hello.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$ hello &> /dev/null &
$ curl_cmd /
Good morning, world!
3 changes: 3 additions & 0 deletions test/cram/2-middleware.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$ middleware &> /dev/null &
$ curl_cmd /
Good morning, world!
3 changes: 3 additions & 0 deletions test/cram/3-router.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$ router &> /dev/null &
$ curl_cmd /echo/hello-world
hello-world
5 changes: 5 additions & 0 deletions test/cram/4-counter.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$ counter &> /dev/null &
$ curl_cmd /
Responding to the 1. request!
$ curl_cmd /
Responding to the 2. request!
6 changes: 6 additions & 0 deletions test/cram/5-promise.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$ promise &> /dev/null &
$ curl_cmd /
0 request(s) successful<br> 0 request(s) failed
$ curl --no-progress-meter localhost:$DREAM_PORT/fail
$ curl_cmd /
1 request(s) successful<br> 1 request(s) failed
3 changes: 3 additions & 0 deletions test/cram/6-echo.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$ echo-server &> /dev/null &
$ curl_cmd /echo --data "Hello, world!"
Hello, world!
8 changes: 8 additions & 0 deletions test/cram/7-template.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$ template &> /dev/null &
$ curl_cmd /hello-world
<html>
<body>
<h1>The URL parameter was hello-world!</h1>
</body>
</html>

Loading
Loading