2

i have this code to start a snap app over 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

Now, when i am browsing with example.com is not forwarded to https://example.com. Is there any builtin functionality to do this?

Deck Pope
  • 231
  • 3
  • 10
  • This may be useful to look at too: https://stackoverflow.com/questions/36732299/how-to-redirect-requests-from-domain-com-to-www-domain-in-wai-warp-app – Chris Stryczynski Jun 11 '17 at 13:30

1 Answers1

1

I'm not too familiar with Snap, I'm guessing you could probably achieve this by adding an additional httpServe for port 80, and then doing a redirect if executed (to the https:// version).

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
  • If it's not possible to run multiple httpServe, you could potentially create a separate application just for this. Or possibly run it in an additional thread. – Chris Stryczynski Jun 13 '17 at 14:24