module Application
( makeApplication
, getApplicationDev
, makeFoundation
) where
import Import
import StaticFiles (staticSite)
import System.Environment (lookupEnv)
import Yesod.Auth (getAuth)
import Yesod.Default.Config
import Yesod.Default.Main
import Yesod.Default.Handlers
import Network.Wai.Middleware.RequestLogger (logStdout, logStdoutDev)
import Network.HTTP.Conduit (newManager, def)
import qualified Data.Text as T
import qualified Network.BSD as NS
import Handler.Abook
import Handler.Compose
import Handler.Home
import Handler.Pager
import Handler.Raw
import Handler.Tags
import Handler.View
mkYesodDispatch "App" resourcesApp
makeApplication :: AppConfig DefaultEnv Extra -> IO Application
makeApplication conf = do
foundation <- makeFoundation conf
app <- toWaiAppPlain foundation
return $ logWare app
where
logWare = if development then logStdoutDev
else logStdout
makeFoundation :: AppConfig DefaultEnv Extra -> IO App
makeFoundation conf = do
manager <- newManager def
s <- staticSite
conf' <- case (extraMessageIDDomain $ appExtra conf) of
"" -> do u <- NS.getHostName
return $ conf { appExtra = (appExtra conf) { extraMessageIDDomain = T.pack u} }
_ -> return conf
conf'' <- case (extraGoogleClientId $ appExtra conf') of
Nothing -> do mi <- lookupEnv "NOTMUCH_WEB_GOOGLE_CLIENTID"
case mi of
Just i -> return $ conf' { appExtra = (appExtra conf') { extraGoogleClientId = Just $ T.pack i } }
Nothing -> return conf'
Just _ -> return conf'
return $ App conf'' s manager $ extraHashedPwd $ appExtra conf''
getApplicationDev :: IO (Int, Application)
getApplicationDev =
defaultDevelApp loader makeApplication
where
loader = loadConfig (configSettings Development)
{ csParseExtra = parseExtra
}