diff options
author | Joey Hess <joey@kitenet.net> | 2012-07-25 21:26:13 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-07-25 21:26:13 -0400 |
commit | 32d3cffc4cf075d7c20fee8addc556f402e94cd2 (patch) | |
tree | 4640fa6618d6c14b652dada4d0423e56ea3a3f95 /Assistant/Threads | |
parent | 03979d4d54e7b0ce76fa296e57b9b5e1820ce7b1 (diff) |
run yesod, and launch webapp on startup
Diffstat (limited to 'Assistant/Threads')
-rw-r--r-- | Assistant/Threads/WebApp.hs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Assistant/Threads/WebApp.hs b/Assistant/Threads/WebApp.hs new file mode 100644 index 000000000..1d9d3cc2f --- /dev/null +++ b/Assistant/Threads/WebApp.hs @@ -0,0 +1,43 @@ +{- git-annex assistant webapp + - + - Copyright 2012 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +{-# LANGUAGE TypeFamilies, QuasiQuotes, MultiParamTypeClasses, TemplateHaskell, OverloadedStrings #-} + +module Assistant.Threads.WebApp where + +import Assistant.Common +import Assistant.DaemonStatus +import Utility.WebApp + +import Yesod + +data WebApp = WebApp DaemonStatusHandle + +mkYesod "WebApp" [parseRoutes| +/ HomeR GET +/config ConfigR GET +|] + +instance Yesod WebApp + +getHomeR :: Handler RepHtml +getHomeR = defaultLayout [whamlet|Hello, World<p><a href=@{ConfigR}>config|] + +getConfigR :: Handler RepHtml +getConfigR = defaultLayout [whamlet|<a href=@{HomeR}>main|] + +webAppThread :: DaemonStatusHandle -> IO () +webAppThread dstatus = do + app <- toWaiApp (WebApp dstatus) + app' <- ifM debugEnabled + ( return $ httpDebugLogger app + , return app + ) + runWebApp app' browser + where + browser p = void $ + runBrowser $ "http://" ++ localhost ++ ":" ++ show p |