2021-05-11 07:04:14 +03:00
..
2021-05-03 09:27:44 +03:00
2021-04-19 00:36:48 +03:00

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!


Up to the tutorial index