Share connection pool with all http clients
This commit is contained in:
@@ -37,6 +37,7 @@ executable dbapi
|
||||
, resource-pool, process
|
||||
, blaze-builder
|
||||
, vector
|
||||
, mtl
|
||||
Other-Modules: App
|
||||
, Auth
|
||||
, Config
|
||||
@@ -81,3 +82,4 @@ Test-Suite spec
|
||||
, resource-pool
|
||||
, blaze-builder
|
||||
, vector
|
||||
, mtl
|
||||
|
||||
+1
-5
@@ -1,5 +1,5 @@
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
module App (runApp, app) where
|
||||
module App (app) where
|
||||
|
||||
import Control.Monad (join)
|
||||
import Data.Monoid ( (<>) )
|
||||
@@ -33,10 +33,6 @@ import RangeQuery
|
||||
import PgStructure
|
||||
import Auth
|
||||
|
||||
runApp :: H.Postgres -> H.SessionSettings -> Application
|
||||
runApp pg sess req respond =
|
||||
respond =<< H.session pg sess (app req)
|
||||
|
||||
app :: Request -> H.Session H.Postgres IO Response
|
||||
app req =
|
||||
case (path, verb) of
|
||||
|
||||
+7
-1
@@ -7,6 +7,8 @@ import App
|
||||
import Middleware
|
||||
|
||||
import Control.Monad (unless)
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import Control.Monad.Reader (runReaderT, ask)
|
||||
import Data.String.Conversions (cs)
|
||||
import Network.Wai.Middleware.Cors (cors)
|
||||
import Network.Wai.Handler.Warp hiding (Connection)
|
||||
@@ -44,7 +46,11 @@ main = do
|
||||
. gzip def . cors corsPolicy . clientErrors
|
||||
. staticPolicy (only [("favicon.ico", "static/favicon.ico")]) in
|
||||
|
||||
runSettings appSettings $ middle (runApp pgSettings sessSettings)
|
||||
H.session pgSettings sessSettings $ do
|
||||
session' <- flip runReaderT <$> ask
|
||||
let runApp req respond = respond =<< session' (app req) in
|
||||
|
||||
liftIO $ runSettings appSettings $ middle runApp
|
||||
-- . authenticated (cs $ configAnonRole conf) $ app
|
||||
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user