Search code examples
haskellhaskell-snap-framework

How can i enable HTTPS over a Snap server?


is there a simple example on enabling HTTPS in a Snap server? I am not that into OpenSsl and its usage with Snap. Thanks


Solution

  • JP Moresmau showed you how to enable it from the command line, but doing the same programatically is just as easy. The function that starts Snap's "main loop" takes a configuration parameter as the first argument as you can see in this bit of documentation. You can simply call defaultConfig from the Snap.Http.Server.Config module and then call setSSLPort, setCert and setSSLKey on it. Then you can pass this new config to httpServe as the first argument. If you used snap init you can find all the relevant code in your src/Main.hs.

    As you can see here, the default config is created from the command line using a description of options. So changing the defaultConfig is exactly the same as passing commandline arguments.

    What I find slightly odd is that there's no defaultSSLConfig that generates a self-signed certificate so you can try SSL quickly. Also, it's odd the certificate and keys are of type FilePath. Maybe it's a good pull request for the Snap team to check?