如何使用warp-tls代替经线scotty?

时间:2015-12-01 22:03:02

标签: haskell scotty haskell-warp

我需要使用warp-tls而不是普通的warp服务器启动我的scotty应用程序,但似乎运行warp在scotty的源代码中是硬连线的。我错过了一些明显的东西吗?

1 个答案:

答案 0 :(得分:2)

您可以使用scottyApp函数代替scotty来获取可以传递给warp Application的WAI runTLS

{-# LANGUAGE OverloadedStrings #-}

import Network.Wai.Handler.WarpTLS (runTLS, tlsSettings)
import Network.Wai.Handler.Warp (defaultSettings, setPort)
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
import Web.Scotty

main :: IO ()
main = do
    let tlsConfig = tlsSettings "your.crt" "your.key"
        config    = setPort 3443 defaultSettings
    waiApp <- scottyApp $ do
        get "/"      (text "hello")
        get "/hello" (text "hello again")
    runTLS tlsConfig config (logStdoutDev waiApp)