Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Warp/Wai and HTTPS -- how to make them work?

I have a basic hello-world application in Haskell Servant and Warp. This is not real code but for the sake of simplicity let's say I'm using it:

import Network.Wai
import Network.Wai.Handler.Warp
import Servant


personAPI :: Proxy PersonAPI
personAPI = Proxy

server :: Server PersonAPI
server = return people

app :: Application
app = serve personAPI server

serveApp :: IO ()
serveApp = run 80 app

It works fine on a server. With http.

I'm not using nginx or apache, I run it as-is and at this point it's fine for me.

But with https it won't load the page. I've installed https certificate but I gathered that I should somehow setup warp/wai to use it, because by default it won't use it. There's shortage of information about this - warp/wai and SSL, I haven't found anything. Could anyone help me?

like image 793
Jushiti Avatar asked Apr 17 '16 11:04

Jushiti


1 Answers

I guess the easiest way is using the warp-tls library - settup your certificate files in the TLSSettings (I would try tlsSettings first) and use runTLS instead of run:

serveApp :: IO ()
serveApp = do
   let tls = tlsSettings "pathToCert" "pathToKey"
   runTLS tls (setPort 443 defaultSettings) app
like image 144
Random Dev Avatar answered Nov 18 '22 23:11

Random Dev