{-# LANGUAGE OverloadedStrings #-} module Server ( runServer, ) where import Data.Semigroup ((<>)) import Data.Text (pack) import Network.Wai (Application) import Network.Wai.Handler.WebSockets (websocketsOr) import Network.WebSockets (ServerApp) import qualified Network.Wai.Handler.Warp as Warp import qualified Network.WebSockets as WebSockets import Logger (Logger, LogLevel(..), postLog) runServer :: Logger -> ServerApp -> Application -> Int -> IO () runServer :: Logger -> ServerApp -> Application -> Int -> IO () runServer Logger logger ServerApp wsApp Application httpApp Int port = let wsConnectionOpts :: ConnectionOptions wsConnectionOpts = ConnectionOptions WebSockets.defaultConnectionOptions in do Logger -> LogLevel -> LogRecord -> IO () postLog Logger logger LogLevel LogInfo (LogRecord -> IO ()) -> LogRecord -> IO () forall a b. (a -> b) -> a -> b $ String -> LogRecord pack (String -> LogRecord) -> String -> LogRecord forall a b. (a -> b) -> a -> b $ String "Listening on port " String -> String -> String forall a. Semigroup a => a -> a -> a <> Int -> String forall a. Show a => a -> String show Int port String -> String -> String forall a. Semigroup a => a -> a -> a <> String "." Int -> Application -> IO () Warp.run Int port (Application -> IO ()) -> Application -> IO () forall a b. (a -> b) -> a -> b $ ConnectionOptions -> ServerApp -> Application -> Application websocketsOr ConnectionOptions wsConnectionOpts ServerApp wsApp Application httpApp