l-https
Enabling HTTPS in Dream is very easy: just pass ~https:true to
Dream.run:
let () =
Dream.run ~https:true
@@ Dream.logger
@@ fun _ -> Dream.html "Good morning, world!"
$ cd example/l-https
$ npm install esy && npx esy
$ npx esy start
However, when you visit https://localhost:8080, you will have to click through a bunch of certificate errors. That's because, by default, Dream uses a compiled-in localhost certificate, which is suitable only for development. The certificate is technically valid, but it is self-signed, and the browser rightly recognizes it as dubious.
For production, be sure to obtain a real certificate, for example, from
Let's Encrypt. Pass the certificate to
Dream.run with ~certificate_file
and ~key_file.
Enabling HTTPS also enables upgrading of connections to HTTP/2, if the client
requests it. Whether HTTP/1.1 or HTTP/2 was used is completely transparent to
the Web app, though it can examine the protocol version by calling
Dream.version on any given
request.
That's all for the tutorial!