haskellsslhttpshaskell-warp

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?


Solution

  • 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