{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
module Boots.Web(
bootWeb
, bootWebEnv
, runContext
, module Boots.Factory.Web
, module Boots.Metrics
, module Boots.Factory.Endpoint
, module Boots.Factory.Trace
, module Boots.Factory.Error
, module Boots.Factory.Random
) where
import Boots.Factory.Web
import Boots.Metrics
import Boots.Factory.Endpoint
import Boots.Factory.Error
import Boots.Factory.Random
import Boots.Factory.Trace
import Boots
import Data.Version (Version)
import Servant.API
import Servant.Server
runContext :: HasContextEntry context env => Context context -> AppT env m () -> m ()
runContext = runAppT . getContextEntry
bootWeb
:: forall api env context
. ( HasServer api context
, HasSwagger api
, HasWeb context env)
=> String
-> Version
-> Factory IO (AppEnv ()) env
-> Factory IO (AppEnv env) (AppEnv env -> Context context)
-> Factory IO (WebEnv env context) ()
-> Proxy api
-> ServerT api (App (AppEnv env))
-> IO ()
bootWeb appName ver fenv fcxt buildCustom api server = bootApp appName ver fenv $ do
conf <- require "application"
ec <- require "endpoints"
store <- liftIO newStore
cxt <- fcxt
env <- getEnv
let
c = newWebEnv env cxt conf ec store :: WebEnv env context
pe = Proxy @env
pc = Proxy @context
within c $ do
tryServeWithSwagger True pc api server
buildError pc pe
buildCustom
buildWebLogger pc pe
buildTrace pc pe
buildRandom pc pe
buildEndpoints pc pe
buildWeb pc pe
bootWebEnv
:: String
-> Version
-> Factory IO (AppEnv ()) env
-> Factory IO (WebEnv env '[AppEnv env]) ()
-> IO ()
bootWebEnv name ver makeExt mid
= bootWeb name ver makeExt (return (:. EmptyContext)) mid (Proxy @EmptyAPI) emptyServer