From e4339fb38d4b5e1773d8ef53058460174eb2411b Mon Sep 17 00:00:00 2001 From: Dennis Frieberg Date: Tue, 22 Sep 2020 16:24:39 +0200 Subject: [PATCH] we have a running webserver (nothing tested) --- app/Main.hs | 15 +++++++++++++-- app/WaiApp.hs | 17 +++++++++++++++++ package.yaml | 4 ++++ tickLeisteServer.cabal | 13 +++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 app/WaiApp.hs diff --git a/app/Main.hs b/app/Main.hs index de1c1ab..9bb883a 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,6 +1,17 @@ module Main where -import Lib +-- TODO: +-- We need some logic to compile with different backends. Right now we only +-- support warp. But a (fast) cgi backend would be nice too. + +-- TODO: +-- We need some way too configure things, like the port we run on. +-- see Network.Wai.Handler.Warp.Settings and Network.Wai.Handler.Warp.runSettings +import WaiApp +import Control.Concurrent.MVar +import Network.Wai.Handler.Warp main :: IO () -main = someFunc +main = do + serverState <- newMVar newServerState + run 8080 $ waiApplication serverState diff --git a/app/WaiApp.hs b/app/WaiApp.hs new file mode 100644 index 0000000..a9b4307 --- /dev/null +++ b/app/WaiApp.hs @@ -0,0 +1,17 @@ +{-# LANGUAGE OverloadedStrings #-} + +module WaiApp (waiApplication, WSA.newServerState, WSA.ServerState) where + +import qualified WebSocketApp as WSA +import qualified Network.WebSockets as WS +import Network.Wai.Handler.WebSockets +import Network.Wai +import Network.HTTP.Types +import Control.Concurrent.MVar + +waiApplication :: MVar WSA.ServerState -> Application +waiApplication serverState = websocketsOr WS.defaultConnectionOptions (WSA.application serverState) clientServer + +-- this should serve the webclient see Network.Wai.responseFile +clientServer :: Application +clientServer _ respond = respond $ responseLBS status404 [] "No webclient implemented (Franzi essen ?? -- Emma)" diff --git a/package.yaml b/package.yaml index 53036a7..7fa081a 100644 --- a/package.yaml +++ b/package.yaml @@ -29,6 +29,10 @@ dependencies: - websockets - bytestring - containers +- wai +- wai-websockets +- http-types +- warp library: source-dirs: src diff --git a/tickLeisteServer.cabal b/tickLeisteServer.cabal index 09739ac..384cdcb 100644 --- a/tickLeisteServer.cabal +++ b/tickLeisteServer.cabal @@ -35,16 +35,21 @@ library , base >=4.7 && <5 , bytestring , containers + , http-types , text , tickLeiste , tickLeiste-aeson , uuid + , wai + , wai-websockets + , warp , websockets default-language: Haskell2010 executable tickLeisteServer main-is: Main.hs other-modules: + WaiApp WebSocketApp Paths_tickLeisteServer hs-source-dirs: @@ -55,11 +60,15 @@ executable tickLeisteServer , base >=4.7 && <5 , bytestring , containers + , http-types , text , tickLeiste , tickLeiste-aeson , tickLeisteServer , uuid + , wai + , wai-websockets + , warp , websockets default-language: Haskell2010 @@ -76,10 +85,14 @@ test-suite tickLeisteServer-test , base >=4.7 && <5 , bytestring , containers + , http-types , text , tickLeiste , tickLeiste-aeson , tickLeisteServer , uuid + , wai + , wai-websockets + , warp , websockets default-language: Haskell2010