65 lines
2.2 KiB
Haskell
65 lines
2.2 KiB
Haskell
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
module Application
|
|
( getApplication
|
|
, getApplicationDev
|
|
) where
|
|
|
|
import Import
|
|
import Settings
|
|
import Settings.StaticFiles (staticSite)
|
|
import Yesod.Auth
|
|
import Yesod.Default.Config
|
|
import Yesod.Default.Main
|
|
import Yesod.Default.Handlers
|
|
#if DEVELOPMENT
|
|
import Yesod.Logger (Logger, logBS)
|
|
import Network.Wai.Middleware.RequestLogger (logHandleDev)
|
|
#else
|
|
import Yesod.Logger (Logger, logBS, toProduction)
|
|
import Network.Wai.Middleware.RequestLogger (logHandle)
|
|
#endif
|
|
import qualified Database.Persist.Store
|
|
import Database.Persist.GenericSql (runMigration)
|
|
import Network.HTTP.Conduit (newManager, def)
|
|
|
|
-- Import all relevant handler modules here.
|
|
import Handler.Root
|
|
|
|
-- 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 "Yosogr" resourcesYosogr
|
|
|
|
-- 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.
|
|
getApplication :: AppConfig DefaultEnv Extra -> Logger -> IO Application
|
|
getApplication conf logger = do
|
|
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
|
|
let foundation = Yosogr conf setLogger s p manager dbconf
|
|
app <- toWaiAppPlain foundation
|
|
return $ logWare app
|
|
where
|
|
#ifdef DEVELOPMENT
|
|
logWare = logHandleDev (logBS setLogger)
|
|
setLogger = logger
|
|
#else
|
|
setLogger = toProduction logger -- by default the logger is set for development
|
|
logWare = logHandle (logBS setLogger)
|
|
#endif
|
|
|
|
-- for yesod devel
|
|
getApplicationDev :: IO (Int, Application)
|
|
getApplicationDev =
|
|
defaultDevelApp loader getApplication
|
|
where
|
|
loader = loadConfig (configSettings Development)
|
|
{ csParseExtra = parseExtra
|
|
}
|