Redirect plain http connections

master
rnhmjoj 2015-08-11 04:06:00 +02:00
parent 0401ccd128
commit 0e4bb4024d
3 changed files with 11 additions and 3 deletions

View File

@ -67,3 +67,10 @@ app url' table = do
json $ object [ "link" .= (url' <> name)
, "name" .= name
, "original" .= url ]
toTLS :: Text -> SpockT IO ()
toTLS host = do
get var (redirect . new)
get "/" (redirect $ new "")
where new url = "https://" <> host <> "/" <> url

View File

@ -45,7 +45,8 @@ settings = do
else base <> ":" <> pack (show port)
return AppSettings
{ bindPort = port
{ bindHost = host
, bindPort = port
, bindUrl = url <> "/"
, urlTable = urls
, tlsSetts = tlsSettings cert key

View File

@ -31,7 +31,7 @@ main = do
AppSettings {..} <- settings
table <- load urlTable
putStrLn ("Serving on " ++ unpack bindUrl)
when (bindPort == 443) (forkIO' $ runTLSRedirect bindHost)
putStrLn ("Serving on " ++ unpack bindUrl)
runBreve tlsSetts bindPort (app bindUrl table)