inmanis/Application.hs

62 lines
2.1 KiB
Haskell
Raw Normal View History

2012-07-02 13:21:39 +00:00
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Application
( makeApplication
, getApplicationDev
, makeFoundation
) where
import Import
import Settings
import Yesod.Auth
import Yesod.Default.Config
import Yesod.Default.Main
import Yesod.Default.Handlers
2012-09-05 06:32:58 +00:00
import Network.Wai.Middleware.RequestLogger (logStdout, logStdoutDev)
2012-07-02 13:21:39 +00:00
import qualified Database.Persist.Store
import Database.Persist.GenericSql (runMigration)
import Network.HTTP.Conduit (newManager, def)
-- Import all relevant handler modules here.
-- Don't forget to add new modules to your cabal file!
import Handler.Home
2012-08-18 19:52:30 +00:00
import Handler.Entry
2012-08-23 12:20:53 +00:00
import Handler.Comment
2012-07-02 13:21:39 +00:00
-- This line actually creates our YesodSite instance. It is the second half
-- of the call to mkYesodData which occurs in Foundation.hs. Please see
-- the comments there for more details.
mkYesodDispatch "App" resourcesApp
-- This function allocates resources (such as a database connection pool),
-- performs initialization and creates a WAI application. This is also the
-- place to put your migrate statements to have automatic database
-- migrations handled by Yesod.
2012-09-05 06:32:58 +00:00
makeApplication :: AppConfig DefaultEnv Extra -> IO Application
makeApplication conf = do
foundation <- makeFoundation conf
2012-07-02 13:21:39 +00:00
app <- toWaiAppPlain foundation
return $ logWare app
where
2012-09-05 06:32:58 +00:00
logWare = if development then logStdoutDev
else logStdout
2012-07-02 13:21:39 +00:00
2012-09-05 06:32:58 +00:00
makeFoundation :: AppConfig DefaultEnv Extra -> IO App
makeFoundation conf = do
2012-07-02 13:21:39 +00:00
manager <- newManager def
s <- staticSite
dbconf <- withYamlEnvironment "config/sqlite.yml" (appEnv conf)
Database.Persist.Store.loadConfig >>=
Database.Persist.Store.applyEnv
p <- Database.Persist.Store.createPoolConfig (dbconf :: Settings.PersistConfig)
Database.Persist.Store.runPool dbconf (runMigration migrateAll) p
2012-09-05 06:32:58 +00:00
return $ App conf s p manager dbconf
2012-07-02 13:21:39 +00:00
-- for yesod devel
getApplicationDev :: IO (Int, Application)
getApplicationDev =
defaultDevelApp loader makeApplication
where
loader = loadConfig (configSettings Development)
{ csParseExtra = parseExtra
}