@@ -35,6 +35,7 @@ import Network.Wai.Handler.Warp.Settings
35import qualified Network.Wai.Handler.Warp.Timeout as T
35import qualified Network.Wai.Handler.Warp.Timeout as T
36import Network.Wai.Handler.Warp.Types
36import Network.Wai.Handler.Warp.Types
37import Network.Wai.Internal (ResponseReceived (ResponseReceived))
37import Network.Wai.Internal (ResponseReceived (ResponseReceived))
38+import System.Environment (getEnvironment)
38import System.IO.Error (isFullErrorType, ioeGetErrorType)
39import System.IO.Error (isFullErrorType, ioeGetErrorType)
40#if WINDOWS
41#if WINDOWS
@@ -71,6 +72,16 @@ allowInterrupt = unblock $ return ()
71run :: Port -> Application -> IO ()
72run :: Port -> Application -> IO ()
72run p = runSettings defaultSettings { settingsPort = p }
73run p = runSettings defaultSettings { settingsPort = p }
75+-- | Run an 'Application' on the port present in the @PORT@ environment variable
77+-- Uses the 'Port' given when the variable is unset.
80+runEnv :: Port -> Application -> IO ()
82+ mp <- fmap (lookup "PORT") getEnvironment
83+ run (maybe p read mp) app
74-- | Run an 'Application' with the given 'Settings'.
85-- | Run an 'Application' with the given 'Settings'.
75runSettings :: Settings -> Application -> IO ()
86runSettings :: Settings -> Application -> IO ()
76runSettings set app = withSocketsDo $
87runSettings set app = withSocketsDo $