25 lines
610 B
Haskell
25 lines
610 B
Haskell
|
module WebServer (runWebServer) where
|
||
|
|
||
|
import ClassyPrelude
|
||
|
import Network.HTTP.Types
|
||
|
import Network.Wai
|
||
|
import Network.Wai.Handler.Warp (run)
|
||
|
import WebSocket (ServerState, broadcast)
|
||
|
|
||
|
app :: MVar ServerState -> Application
|
||
|
app state _ respond = do
|
||
|
putStrLn "I've done some IO here"
|
||
|
currentState <- takeMVar state
|
||
|
broadcast "dsa" currentState
|
||
|
putMVar state currentState
|
||
|
respond $
|
||
|
responseLBS
|
||
|
status200
|
||
|
[("Content-Type", "text/plain")]
|
||
|
"Hello, Web!"
|
||
|
|
||
|
runWebServer :: MVar ServerState -> IO ()
|
||
|
runWebServer state = do
|
||
|
putStrLn $ "http://localhost:8080/"
|
||
|
run 8080 $ app state
|