aboutsummaryrefslogtreecommitdiff
path: root/lib/Server/Util.hs
blob: 1c62663f86d6508ecfcaa0cc4e6a242dab24de57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{-# LANGUAGE FlexibleContexts #-}

-- | mostly the monad the service runs in
module Server.Util (Service, ServiceM, runService, redirect) where

import           Control.Monad.Logger (LoggingT, runStderrLoggingT)
import           Data.ByteString      (ByteString)
import           Servant              (Handler, ServerError, ServerT, err302,
                                       errHeaders, throwError)

type ServiceM  = LoggingT Handler
type Service api = ServerT api ServiceM

runService :: ServiceM a -> Handler a
runService = runStderrLoggingT

redirect :: ByteString -> ServiceM a
redirect path = throwError $ err302 { errHeaders = [("Location", path)] }