New sig for basicHandler
This commit is contained in:
parent
5cdd7c82d7
commit
a14f232f18
@ -16,6 +16,7 @@ module Yesod.Dispatch
|
|||||||
-- * Convert to WAI
|
-- * Convert to WAI
|
||||||
, toWaiApp
|
, toWaiApp
|
||||||
, basicHandler
|
, basicHandler
|
||||||
|
, basicHandler'
|
||||||
-- * Utilities
|
-- * Utilities
|
||||||
, fullRender
|
, fullRender
|
||||||
#if TEST
|
#if TEST
|
||||||
@ -307,13 +308,29 @@ httpAccept = map B.unpack
|
|||||||
|
|
||||||
-- | Runs an application with CGI if CGI variables are present (namely
|
-- | Runs an application with CGI if CGI variables are present (namely
|
||||||
-- PATH_INFO); otherwise uses SimpleServer.
|
-- PATH_INFO); otherwise uses SimpleServer.
|
||||||
basicHandler :: Int -- ^ port number
|
basicHandler :: (Yesod y, YesodSite y)
|
||||||
-> W.Application -> IO ()
|
=> Int -- ^ port number
|
||||||
basicHandler port app = do
|
-> 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
|
vars <- getEnvironment
|
||||||
case lookup "PATH_INFO" vars of
|
case lookup "PATH_INFO" vars of
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
putStrLn $ "http://localhost:" ++ show port ++ "/"
|
case mhost of
|
||||||
|
Nothing -> return ()
|
||||||
|
Just h -> putStrLn $ concat
|
||||||
|
["http://", h, ":", show port, "/"]
|
||||||
SS.run port app
|
SS.run port app
|
||||||
Just _ -> CGI.run app
|
Just _ -> CGI.run app
|
||||||
|
|
||||||
|
|||||||
@ -64,7 +64,7 @@ handleFormR = do
|
|||||||
|]
|
|]
|
||||||
setTitle $ string "Form"
|
setTitle $ string "Form"
|
||||||
|
|
||||||
main = toWaiApp (HW $ fileLookupDir "static" typeByExt) >>= basicHandler 3000
|
main = basicHandler 3000 $ HW $ fileLookupDir "static" typeByExt
|
||||||
|
|
||||||
getAutoCompleteR :: Handler HW RepJson
|
getAutoCompleteR :: Handler HW RepJson
|
||||||
getAutoCompleteR = do
|
getAutoCompleteR = do
|
||||||
|
|||||||
@ -4,4 +4,4 @@ data HelloWorld = HelloWorld
|
|||||||
mkYesod "HelloWorld" [$parseRoutes|/ Home GET|]
|
mkYesod "HelloWorld" [$parseRoutes|/ Home GET|]
|
||||||
instance Yesod HelloWorld where approot _ = ""
|
instance Yesod HelloWorld where approot _ = ""
|
||||||
getHome = return $ RepPlain $ toContent "Hello World!"
|
getHome = return $ RepPlain $ toContent "Hello World!"
|
||||||
main = toWaiApp HelloWorld >>= basicHandler 3000
|
main = basicHandler 3000 HelloWorld
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user