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.Handler
import Yesod.Widget
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Text (Text)
import Control.Monad (liftM, mzero, when)
import Data.Monoid (mappend)

View File

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

View File

@ -20,6 +20,7 @@ import Yesod.Logger (Logger)
import Network.Wai.Middleware.RequestLogger (logStdout)
#endif
import qualified Database.Persist.Store~importMigration~
import Network.HTTP.Conduit (withManager)
-- Import all relevant handler modules here.
import Handler.Root
@ -34,12 +35,12 @@ mkYesodDispatch "~sitearg~" resources~sitearg~
-- place to put your migrate statements to have automatic database
-- migrations handled by Yesod.
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
dbconf <- withYamlEnvironment "config/~dbConfigFile~.yml" (appEnv conf)
Database.Persist.Store.loadConfig
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
where
#ifdef DEVELOPMENT

View File

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

View File

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

View File

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