Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 294
Deck Pope Avatar asked Sep 07 '26 19:09

Deck Pope


1 Answers

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?

like image 127
Juan Pablo Santos Avatar answered Sep 11 '26 19:09

Juan Pablo Santos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!