Use pooling and add a general Reader record to the stack by default
This commit is contained in:
16
src/Main.hs
16
src/Main.hs
@@ -9,6 +9,7 @@ import Data.List
|
||||
import Effectful
|
||||
import Effectful.Error.Static (Error, runError, runErrorNoCallStack, throwError)
|
||||
import Effectful.FileSystem
|
||||
import Effectful.Reader.Static
|
||||
import Network.Wai.Handler.Warp (run)
|
||||
import Servant hiding ((:>), throwError)
|
||||
import qualified Servant as S
|
||||
@@ -17,22 +18,27 @@ import qualified Servant as S
|
||||
-- Application
|
||||
--
|
||||
main :: IO ()
|
||||
main = run port $ serve proxy app
|
||||
main = do
|
||||
pool <- createConnectionPool
|
||||
let env = AppEnv { pool = pool }
|
||||
run port $ serve proxy $ app env
|
||||
|
||||
app :: Server AppAPI
|
||||
app = α $ rootHandler
|
||||
app :: AppEnv -> Server AppAPI
|
||||
app env = transformEff env
|
||||
$ rootHandler
|
||||
:<|> userListHandler
|
||||
:<|> userGetHandler
|
||||
:<|> userPostHandler
|
||||
|
||||
α :: ServerT AppAPI AppEff -> ServerT AppAPI Handler
|
||||
α = hoistServer proxy
|
||||
transformEff :: AppEnv -> ServerT AppAPI AppEff -> ServerT AppAPI Handler
|
||||
transformEff env = hoistServer proxy
|
||||
$ Handler
|
||||
. ExceptT
|
||||
. runEff
|
||||
. runErrorNoCallStack
|
||||
. runLoggerIO
|
||||
. runFileSystem
|
||||
. runReader env
|
||||
. runDatabaseIO
|
||||
|
||||
port :: Int
|
||||
|
||||
Reference in New Issue
Block a user