From 8793cffe471c5f5deb903bd215e086cab167e4f8 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Mon, 24 Sep 2012 15:57:01 +0200 Subject: [PATCH] warpEnv --- yesod-form/yesod-form.cabal | 2 +- yesod/Yesod.hs | 16 ++++++++++++++++ yesod/yesod.cabal | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/yesod-form/yesod-form.cabal b/yesod-form/yesod-form.cabal index ad7ddcf4..05199e9d 100644 --- a/yesod-form/yesod-form.cabal +++ b/yesod-form/yesod-form.cabal @@ -1,5 +1,5 @@ name: yesod-form -version: 1.1.2 +version: 1.1.3 license: MIT license-file: LICENSE author: Michael Snoyman diff --git a/yesod/Yesod.hs b/yesod/Yesod.hs index a7885130..aafbafe7 100644 --- a/yesod/Yesod.hs +++ b/yesod/Yesod.hs @@ -10,6 +10,7 @@ module Yesod -- * Running your application , warp , warpDebug + , warpEnv , develServer -- * Commonly referenced functions/datatypes , Application @@ -58,6 +59,8 @@ import Text.Blaze.Html (toHtml) import Text.Blaze (toHtml) #endif +import System.Environment (getEnv) + showIntegral :: Integral a => a -> String showIntegral x = show (fromIntegral x :: Integer) @@ -80,6 +83,19 @@ warpDebug port app = do waiApp <- toWaiApp app run port $ logStdout waiApp +-- | Runs your application using default middlewares (i.e., via 'toWaiApp'). It +-- reads port information from the PORT environment variable, as used by tools +-- such as Keter. +-- +-- Note that the exact behavior of this function may be modified slightly over +-- time to work correctly with external tools, without a change to the type +-- signature. +warpEnv :: (Yesod a, YesodDispatch a a) => a -> IO () +warpEnv master = do + port <- getEnv "PORT" >>= readIO + app <- toWaiApp master + run port app + -- | Run a development server, where your code changes are automatically -- reloaded. develServer :: Int -- ^ port number diff --git a/yesod/yesod.cabal b/yesod/yesod.cabal index 003b2629..a16030e5 100644 --- a/yesod/yesod.cabal +++ b/yesod/yesod.cabal @@ -1,5 +1,5 @@ name: yesod -version: 1.1.0.3 +version: 1.1.1 license: MIT license-file: LICENSE author: Michael Snoyman