2015-08-17 23:56:29 +02:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
{-# LANGUAGE DataKinds #-}
|
2015-07-22 23:50:03 +02:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2015-08-17 23:56:29 +02:00
|
|
|
{-# LANGUAGE TypeOperators #-}
|
2015-07-22 23:50:03 +02:00
|
|
|
|
|
|
|
|
2015-08-17 23:56:29 +02:00
|
|
|
import Data.Monoid ((<>))
|
2015-07-22 23:50:03 +02:00
|
|
|
#if !MIN_VERSION_base(4,8,0)
|
2015-08-17 23:56:29 +02:00
|
|
|
import Control.Applicative ((<$>))
|
2015-07-22 23:50:03 +02:00
|
|
|
#endif
|
2015-08-17 23:56:29 +02:00
|
|
|
import Network.EngineIO.Wai
|
|
|
|
import Network.Wai
|
|
|
|
import Network.Wai.Handler.Warp (run)
|
|
|
|
import Servant
|
2015-07-22 23:50:03 +02:00
|
|
|
|
|
|
|
|
2015-08-17 23:56:29 +02:00
|
|
|
import qualified Control.Concurrent.STM as STM
|
|
|
|
import qualified Network.SocketIO as SocketIO
|
2015-07-22 23:50:03 +02:00
|
|
|
|
|
|
|
|
2015-08-17 23:56:29 +02:00
|
|
|
import Chat (ServerState (..), eioServer)
|
2015-07-22 23:50:03 +02:00
|
|
|
|
|
|
|
|
2015-08-10 17:21:06 +02:00
|
|
|
type API = "socket.io" :> Raw IO Application
|
|
|
|
:<|> Raw IO Application
|
2015-07-22 23:50:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
api :: Proxy API
|
|
|
|
api = Proxy
|
|
|
|
|
|
|
|
|
|
|
|
server :: WaiMonad () -> Server API
|
|
|
|
server sHandler = socketIOHandler
|
|
|
|
:<|> serveDirectory "socket-io-chat/resources"
|
|
|
|
|
|
|
|
where
|
2015-07-31 19:21:28 +02:00
|
|
|
socketIOHandler = Raw $ toWaiApplication sHandler
|
2015-07-22 23:50:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
app :: WaiMonad () -> Application
|
|
|
|
app sHandler = serve api $ server sHandler
|
|
|
|
|
|
|
|
port :: Int
|
|
|
|
port = 3001
|
|
|
|
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
state <- ServerState <$> STM.newTVarIO 0
|
|
|
|
sHandler <- SocketIO.initialize waiAPI (eioServer state)
|
|
|
|
putStrLn $ "Running on " <> show port
|
|
|
|
run port $ app sHandler
|
|
|
|
|
|
|
|
|