aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile3
-rw-r--r--server/cafp.cabal21
-rw-r--r--server/lib/Cafp/Main/GenerateElmTypes.hs17
-rw-r--r--server/lib/Cafp/Main/Server.hs29
-rw-r--r--server/src/GenerateElmTypes.hs13
-rw-r--r--server/src/Server.hs4
6 files changed, 70 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 9260540..677f1b6 100644
--- a/Makefile
+++ b/Makefile
@@ -5,5 +5,8 @@ ELM_MESSAGES_MODULE=client/src/Messages.elm
build:
cd server && stack build
+server: build
+ cd server && stack exec cafp-server
+
$(ELM_MESSAGES_MODULE): $(HS_SOURCES)
(cd server && stack exec cafp-generate-elm-types) >$(ELM_MESSAGES_MODULE)
diff --git a/server/cafp.cabal b/server/cafp.cabal
index fc52b4f..805979f 100644
--- a/server/cafp.cabal
+++ b/server/cafp.cabal
@@ -17,18 +17,27 @@ Library
Exposed-modules:
Cafp.Messages
+ Cafp.Main.GenerateElmTypes
+ Cafp.Main.Server
Build-depends:
- base >= 4.9 && < 5,
- elm-bridge >= 0.5 && < 0.6
+ base >= 4.9 && < 5,
+ elm-bridge >= 0.5 && < 0.6,
+ scotty >= 0.11 && < 0.12,
+ stm >= 2.5 && < 2.6,
+ text >= 1.2 && < 1.3,
+ unordered-containers >= 0.2 && < 0.3
Executable cafp-generate-elm-types
Hs-source-dirs: src
Main-is: GenerateElmTypes.hs
Default-language: Haskell2010
Ghc-options: -Wall
+ Build-depends: base, cafp
- Build-depends:
- base >= 4.9 && < 5,
- cafp,
- elm-bridge >= 0.5 && < 0.6
+Executable cafp-server
+ Hs-source-dirs: src
+ Main-is: Server.hs
+ Default-language: Haskell2010
+ Ghc-options: -Wall
+ Build-depends: base, cafp
diff --git a/server/lib/Cafp/Main/GenerateElmTypes.hs b/server/lib/Cafp/Main/GenerateElmTypes.hs
new file mode 100644
index 0000000..0bd43c1
--- /dev/null
+++ b/server/lib/Cafp/Main/GenerateElmTypes.hs
@@ -0,0 +1,17 @@
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+{-# LANGUAGE TemplateHaskell #-}
+module Cafp.Main.GenerateElmTypes
+ ( main
+ ) where
+
+import Cafp.Messages
+import Elm.Derive
+import Elm.Module
+import Data.Proxy
+
+deriveBoth defaultOptions ''ServerMessage
+
+main :: IO ()
+main = putStrLn $ makeElmModule "Messages"
+ [ DefineElm (Proxy :: Proxy ServerMessage)
+ ]
diff --git a/server/lib/Cafp/Main/Server.hs b/server/lib/Cafp/Main/Server.hs
new file mode 100644
index 0000000..a2561a3
--- /dev/null
+++ b/server/lib/Cafp/Main/Server.hs
@@ -0,0 +1,29 @@
+{-# LANGUAGE OverloadedStrings #-}
+module Cafp.Main.Server
+ ( main
+ ) where
+
+import Cafp.Messages
+import Control.Concurrent.STM (STM, TVar, newTVar)
+import Control.Monad (when)
+import qualified Data.HashMap.Strict as HMS
+import qualified Data.Text as T
+import qualified Data.Text.Lazy as TL
+import qualified Web.Scotty as Scotty
+
+type RoomId = T.Text
+
+data Server = Server
+ { serverRooms :: TVar (HMS.HashMap RoomId ())
+ }
+
+newServer :: STM Server
+newServer = Server <$> newTVar HMS.empty
+
+main :: IO ()
+main = Scotty.scotty 3000 $ do
+ Scotty.get "/rooms/:id" $ do
+ roomId <- Scotty.param "id"
+ when (T.length roomId < 6) $
+ Scotty.raise "Room ID should be at least 6 characters"
+ Scotty.html $ "<h1>Scotty, " <> TL.fromStrict roomId <> " me up!</h1>"
diff --git a/server/src/GenerateElmTypes.hs b/server/src/GenerateElmTypes.hs
index e8aa25b..c85aaf3 100644
--- a/server/src/GenerateElmTypes.hs
+++ b/server/src/GenerateElmTypes.hs
@@ -1,13 +1,4 @@
-{-# OPTIONS_GHC -fno-warn-orphans #-}
-{-# LANGUAGE TemplateHaskell #-}
-import Cafp.Messages
-import Elm.Derive
-import Elm.Module
-import Data.Proxy
-
-deriveBoth defaultOptions ''ServerMessage
+import qualified Cafp.Main.GenerateElmTypes
main :: IO ()
-main = putStrLn $ makeElmModule "Messages"
- [ DefineElm (Proxy :: Proxy ServerMessage)
- ]
+main = Cafp.Main.GenerateElmTypes.main
diff --git a/server/src/Server.hs b/server/src/Server.hs
new file mode 100644
index 0000000..fba65ef
--- /dev/null
+++ b/server/src/Server.hs
@@ -0,0 +1,4 @@
+import qualified Cafp.Main.Server
+
+main :: IO ()
+main = Cafp.Main.Server.main