Scaffolding provides Manager

This commit is contained in:
Michael Snoyman 2012-01-10 11:57:08 +02:00
parent 1b3eb2b282
commit 6d30eabd7c
6 changed files with 12 additions and 10 deletions

View File

@ -20,7 +20,6 @@ import Data.Maybe (fromMaybe)
import Yesod.Form import Yesod.Form
import Yesod.Handler import Yesod.Handler
import Yesod.Widget import Yesod.Widget
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Text (Text) import Data.Text (Text)
import Control.Monad (liftM, mzero, when) import Control.Monad (liftM, mzero, when)
import Data.Monoid (mappend) import Data.Monoid (mappend)

View File

@ -15,7 +15,6 @@ import Yesod.Handler
import Yesod.Widget import Yesod.Widget
import Yesod.Request import Yesod.Request
import Text.Hamlet (hamlet) import Text.Hamlet (hamlet)
import Control.Monad.IO.Class (liftIO)
import Data.Text (pack, unpack) import Data.Text (pack, unpack)
import Control.Arrow ((***)) import Control.Arrow ((***))

View File

@ -20,6 +20,7 @@ import Yesod.Logger (Logger)
import Network.Wai.Middleware.RequestLogger (logStdout) import Network.Wai.Middleware.RequestLogger (logStdout)
#endif #endif
import qualified Database.Persist.Store~importMigration~ import qualified Database.Persist.Store~importMigration~
import Network.HTTP.Conduit (withManager)
-- Import all relevant handler modules here. -- Import all relevant handler modules here.
import Handler.Root import Handler.Root
@ -34,12 +35,12 @@ mkYesodDispatch "~sitearg~" resources~sitearg~
-- place to put your migrate statements to have automatic database -- place to put your migrate statements to have automatic database
-- migrations handled by Yesod. -- migrations handled by Yesod.
with~sitearg~ :: AppConfig DefaultEnv Extra -> Logger -> (Application -> IO ()) -> IO () with~sitearg~ :: AppConfig DefaultEnv Extra -> Logger -> (Application -> IO ()) -> IO ()
with~sitearg~ conf logger f = do with~sitearg~ conf logger f = withManager $ \manager -> lift $ do
s <- staticSite s <- staticSite
dbconf <- withYamlEnvironment "config/~dbConfigFile~.yml" (appEnv conf) dbconf <- withYamlEnvironment "config/~dbConfigFile~.yml" (appEnv conf)
Database.Persist.Store.loadConfig Database.Persist.Store.loadConfig
Database.Persist.Store.withPool (dbconf :: Settings.PersistConfig) $ \p -> do~runMigration~ Database.Persist.Store.withPool (dbconf :: Settings.PersistConfig) $ \p -> do~runMigration~
let h = ~sitearg~ conf logger s p let h = ~sitearg~ conf logger s p manager
defaultRunner (f . logWare) h defaultRunner (f . logWare) h
where where
#ifdef DEVELOPMENT #ifdef DEVELOPMENT

View File

@ -1,6 +1,6 @@
module Foundation module Foundation
( ~sitearg~ (..) ( ~sitearg~ (..)
, ~sitearg~Route (..) , Route (..)
, ~sitearg~Message (..) , ~sitearg~Message (..)
, resources~sitearg~ , resources~sitearg~
, Handler , Handler
@ -11,13 +11,11 @@ module Foundation
, module Yesod , module Yesod
, module Settings , module Settings
, module Model , module Model
, StaticRoute (..)
, AuthRoute (..)
) where ) where
import Prelude import Prelude
import Yesod import Yesod
import Yesod.Static (Static, base64md5, StaticRoute(..)) import Yesod.Static
import Settings.StaticFiles import Settings.StaticFiles
import Yesod.Auth import Yesod.Auth
import Yesod.Auth.BrowserId import Yesod.Auth.BrowserId
@ -25,6 +23,7 @@ import Yesod.Auth.GoogleEmail
import Yesod.Default.Config import Yesod.Default.Config
import Yesod.Default.Util (addStaticContentExternal) import Yesod.Default.Util (addStaticContentExternal)
import Yesod.Logger (Logger, logMsg, formatLogText) import Yesod.Logger (Logger, logMsg, formatLogText)
import Network.HTTP.Conduit (Manager)
#ifdef DEVELOPMENT #ifdef DEVELOPMENT
import Yesod.Logger (logLazyText) import Yesod.Logger (logLazyText)
#endif #endif
@ -52,6 +51,7 @@ data ~sitearg~ = ~sitearg~
, getLogger :: Logger , getLogger :: Logger
, getStatic :: Static -- ^ Settings for static file serving. , getStatic :: Static -- ^ Settings for static file serving.
, connPool :: Database.Persist.Store.PersistConfigPool Settings.PersistConfig -- ^ Database connection pool. , connPool :: Database.Persist.Store.PersistConfigPool Settings.PersistConfig -- ^ Database connection pool.
, httpManager :: Manager
} }
-- Set up i18n messages. See the message folder. -- Set up i18n messages. See the message folder.
@ -140,13 +140,15 @@ instance YesodAuth ~sitearg~ where
getAuthId creds = runDB $ do getAuthId creds = runDB $ do
x <- getBy $ UniqueUser $ credsIdent creds x <- getBy $ UniqueUser $ credsIdent creds
case x of case x of
Just (uid, _) -> return $ Just uid Just (Entity uid _) -> return $ Just uid
Nothing -> do Nothing -> do
fmap Just $ insert $ User (credsIdent creds) Nothing fmap Just $ insert $ User (credsIdent creds) Nothing
-- You can add other plugins like BrowserID, email or OAuth here -- You can add other plugins like BrowserID, email or OAuth here
authPlugins = [authBrowserId, authGoogleEmail] authPlugins = [authBrowserId, authGoogleEmail]
authHttpManager = httpManager
-- Sends off your mail. Requires sendmail in production! -- Sends off your mail. Requires sendmail in production!
deliver :: ~sitearg~ -> L.ByteString -> IO () deliver :: ~sitearg~ -> L.ByteString -> IO ()
#ifdef DEVELOPMENT #ifdef DEVELOPMENT

View File

@ -1,7 +1,7 @@
module Settings.StaticFiles where module Settings.StaticFiles where
import Prelude (IO) import Prelude (IO)
import Yesod.Static (staticFiles, StaticRoute (StaticRoute)) import Yesod.Static
import qualified Yesod.Static as Static import qualified Yesod.Static as Static
import Settings (staticDir) import Settings (staticDir)

View File

@ -95,4 +95,5 @@ executable ~project~
, monad-control >= 0.3 && < 0.4 , monad-control >= 0.3 && < 0.4
, wai-extra >= 1.0 && < 1.1 , wai-extra >= 1.0 && < 1.1
, yaml >= 0.5 && < 0.6 , yaml >= 0.5 && < 0.6
, http-conduit >= 1.1 && < 1.2