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

1

12

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?

Carpo answered 17/4, 2016 at 11:17 Comment(0)
R
12

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
Rhodes answered 17/4, 2016 at 11:43 Comment(7)
you know everything!Carpo
but at warp-tls it says "Support for SSL is now obsoleted. " and SSL is what I need.Carpo
I can assure you I know very little (beside how to enter queries into Hayoo ;))Rhodes
I've never heard of Hayoo before, that's not me.Carpo
well maybe they moved it somewhere else but it should still workRhodes
it's like Hoogle but searches more packages by defaultRhodes
I looked around a bit and I think the comment in the package is a bit misleading: yesodweb.com/blog/2015/07/http2 (if I get it correctly it means that current browsers will establish TLS over the headers so you probably don't need the open 443 port anymore and can use 80(?) - as I said: I am no expert on this)Rhodes

© 2022 - 2024 — McMap. All rights reserved.