module Snap.Http.Server.Env
( httpServe
, module Snap.Http.Server
) where
import Safe (readMay)
import Snap.Core (Snap)
import Snap.Http.Server hiding (httpServe)
import qualified Snap.Http.Server as Snap
import System.Environment (getEnvironment)
httpServe :: Config Snap a -> Snap () -> IO ()
httpServe config snap = do
env <- getEnvironment
case lookup "PORT" env of
Nothing -> error "PORT environment variable not found"
Just portS ->
case readMay portS of
Nothing -> error $ "Invalid PORT enviornment variable: " ++ portS
Just port -> Snap.httpServe (setPort port config) snap