yesod devel does not have a hard-coded port

This commit is contained in:
Michael Snoyman 2011-08-22 08:28:49 +03:00
parent 56a5b167a6
commit d535720a0b
2 changed files with 15 additions and 14 deletions

View File

@ -83,7 +83,7 @@ devel cabalCmd = do
, concat
[ "import \""
, pi'
, "\" Handler (withDevelApp)"
, "\" Handler (withDevelAppPort)"
]
, "import Data.Dynamic (fromDynamic)"
, "import Network.Wai.Handler.Warp (run)"
@ -96,7 +96,8 @@ devel cabalCmd = do
, "main :: IO ()"
, "main = do"
, " putStrLn \"Starting app\""
, " forkIO $ (fromJust $ fromDynamic withDevelApp) $ run 3000"
, " wdap <- return $ fromJust $ fromDynamic withDevelAppPort"
, " forkIO $ wdap $ \\(port, app) -> run port app"
, " loop"
, ""
, "loop :: IO ()"

View File

@ -5,7 +5,7 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Handler
( with~sitearg~
, withDevelApp
, withDevelAppPort
) where
import ~sitearg~
@ -62,15 +62,15 @@ with~sitearg~ conf logger f = do
where
s = static Settings.staticDir
with~sitearg~LoadConfig :: Settings.AppEnvironment -> (Application -> IO a) -> IO ()
with~sitearg~LoadConfig env f = do
conf <- Settings.loadConfig env
logger <- makeLogger
with~sitearg~ conf logger f
flushLogger logger
-- for yesod devel
withDevelApp :: Dynamic
withDevelApp = do
toDyn ((with~sitearg~LoadConfig Settings.Development):: (Application -> IO ()) -> IO ())
withDevelAppPort :: Dynamic
withDevelAppPort =
toDyn go
where
go :: ((Int, Application) -> IO ()) -> IO ()
go f = do
conf <- Settings.loadConfig Settings.Development
let port = appPort conf
logger <- makeLogger
with~sitearg~ conf logger $ \app -> f (port, app)
flushLogger logger