diff --git a/Yesod/Dispatch.hs b/Yesod/Dispatch.hs index 3d08ccd0..9363c5c4 100644 --- a/Yesod/Dispatch.hs +++ b/Yesod/Dispatch.hs @@ -16,6 +16,7 @@ module Yesod.Dispatch -- * Convert to WAI , toWaiApp , basicHandler + , basicHandler' -- * Utilities , fullRender #if TEST @@ -307,13 +308,29 @@ httpAccept = map B.unpack -- | Runs an application with CGI if CGI variables are present (namely -- PATH_INFO); otherwise uses SimpleServer. -basicHandler :: Int -- ^ port number - -> W.Application -> IO () -basicHandler port app = do +basicHandler :: (Yesod y, YesodSite y) + => Int -- ^ port number + -> y + -> IO () +basicHandler port y = basicHandler' port (Just "localhost") y + + +-- | Same as 'basicHandler', but allows you to specify the hostname to display +-- to the user. If 'Nothing' is provided, then no output is produced. +basicHandler' :: (Yesod y, YesodSite y) + => Int -- ^ port number + -> Maybe String -- ^ host name, 'Nothing' to show nothing + -> y + -> IO () +basicHandler' port mhost y = do + app <- toWaiApp y vars <- getEnvironment case lookup "PATH_INFO" vars of Nothing -> do - putStrLn $ "http://localhost:" ++ show port ++ "/" + case mhost of + Nothing -> return () + Just h -> putStrLn $ concat + ["http://", h, ":", show port, "/"] SS.run port app Just _ -> CGI.run app diff --git a/hellowidget.hs b/hellowidget.hs index a223effa..11a330a0 100644 --- a/hellowidget.hs +++ b/hellowidget.hs @@ -64,7 +64,7 @@ handleFormR = do |] setTitle $ string "Form" -main = toWaiApp (HW $ fileLookupDir "static" typeByExt) >>= basicHandler 3000 +main = basicHandler 3000 $ HW $ fileLookupDir "static" typeByExt getAutoCompleteR :: Handler HW RepJson getAutoCompleteR = do diff --git a/helloworld.hs b/helloworld.hs index 2e26b7a8..2a3f8723 100644 --- a/helloworld.hs +++ b/helloworld.hs @@ -4,4 +4,4 @@ data HelloWorld = HelloWorld mkYesod "HelloWorld" [$parseRoutes|/ Home GET|] instance Yesod HelloWorld where approot _ = "" getHome = return $ RepPlain $ toContent "Hello World!" -main = toWaiApp HelloWorld >>= basicHandler 3000 +main = basicHandler 3000 HelloWorld