使用Snap重定向到https

时间:2017-06-09 13:43:38

标签: haskell https haskell-snap-framework

我有这个代码通过https启动快照应用程序:

main :: IO ()
main = do
  -- get the port from the ENV , it should be in /etc/profile as any other ENV variable or $ export BIND_PORT=8000
  a <- lookupEnv "BIND_PORT"
  let port = displayResult a
  liftIO $ createDirectoryIfMissing True "img"
  httpServe (setPort (read port) config) Main.skite
    where
     config =
         setSSLPort 443 $
         setSSLCert "/etc/letsencrypt/../cert.pem" $
         setSSLKey "/etc/letsencrypt/../privkey.pem" $
         setSSLBind "0.0.0.0" $
         setSSLChainCert False $
         defaultConfig

skite :: Snap ()
skite = do
    req <- fmap rqHostName getRequest
    reqPath <- fmap rqPathInfo getRequest
    routes req reqPath
  where
    routes req reqPath =
        Rain.skite

现在,当我使用example.com进行浏览时,不会转发到https://example.com。是否有内置功能来执行此操作?

1 个答案:

答案 0 :(得分:1)

我对Snap不太熟悉,我猜你可以通过为端口80添加额外的httpServe来实现这一点,然后在执行时进行重定向(到https://版本) 。