module Network.PinPon.API
(
API
, app
, api
, server
)
where
import Protolude
import Control.Monad.Reader (runReaderT)
import Control.Monad.Trans.Resource (runResourceT)
import Network.Wai (Application)
import Servant
((:~>)(..), Handler, Proxy(..), Server, enter, serve)
import Network.PinPon.API.Topic (TopicAPI, topicServer)
import Network.PinPon.Config (App(..), Config(..))
type API = TopicAPI
api :: Proxy API
api = Proxy
appToHandler :: Config -> App :~> Handler
appToHandler config = NT $ \a -> runResourceT (runReaderT (runApp a) config)
server :: Config -> Server API
server config = enter (appToHandler config) topicServer
app :: Config -> Application
app = serve api . server