Skip to content

Commit

Permalink
Support building with scotty-0.20
Browse files Browse the repository at this point in the history
Fixes #10.
  • Loading branch information
RyanGlScott committed Oct 5, 2023
1 parent 8cbd592 commit 70ff635
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## next [????.??.??]
* Support building with `scotty-0.20`.

## 0.4.1 [2021.10.09]
* Allow building with `aeson-2.0.0.0`.

Expand Down
17 changes: 12 additions & 5 deletions Web/Scotty/Comet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module Web.Scotty.Comet
, defaultOptions
) where

import Web.Scotty (ScottyM, text, post, capture, param, setHeader, get, ActionM, jsonData)
import qualified Web.Scotty as Scotty
import Web.Scotty (ScottyM, text, post, capture, setHeader, get, ActionM, jsonData)
import Data.Aeson (Value(..))
import Control.Monad
import Control.Concurrent.STM as STM
Expand Down Expand Up @@ -104,7 +105,7 @@ connect opt callback = do
get (capture $ prefix opt ++ "/act/" ++ server_id ++ "/:id/:act") $ do
setHeader "Cache-Control" "max-age=0, no-cache, private, no-store, must-revalidate"
-- do something and return a new list of commands to the client
num <- param "id"
num <- captureParam "id"

when (verbose opt >= 2) $ liftIO $ putStrLn $
"Kansas Comet: get .../act/" ++ show num
Expand Down Expand Up @@ -141,8 +142,8 @@ connect opt callback = do

post (capture $ prefix opt ++ "/reply/" ++ server_id ++ "/:id/:uq") $ do
setHeader "Cache-Control" "max-age=0, no-cache, private, no-store, must-revalidate"
num <- param "id"
uq :: Int <- param "uq"
num <- captureParam "id"
uq :: Int <- captureParam "uq"
--liftIO $ print (num :: Int, event :: String)

when (verbose opt >= 2) $ liftIO $ putStrLn $
Expand Down Expand Up @@ -171,7 +172,7 @@ connect opt callback = do

post (capture $ prefix opt ++ "/event/" ++ server_id ++ "/:id") $ do
setHeader "Cache-Control" "max-age=0, no-cache, private, no-store, must-revalidate"
num <- param "id"
num <- captureParam "id"

when (verbose opt >= 2) $ liftIO $ putStrLn $
"Kansas Comet: post .../event/" ++ show num
Expand Down Expand Up @@ -202,6 +203,12 @@ connect opt callback = do
lookupKM = HashMap.lookup
#endif

#if MIN_VERSION_scotty(0,20,0)
captureParam = Scotty.captureParam
#else
captureParam = Scotty.param
#endif

-- | 'kCometPlugin' provides the location of the Kansas Comet jQuery plugin.
kCometPlugin :: IO String
kCometPlugin = getDataFileName "static/js/kansas-comet.js"
Expand Down
2 changes: 1 addition & 1 deletion example/kansas-comet-example.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Executable kansas-comet-example
base-compat-batteries >= 0.10 && < 0.14,
aeson >= 0.9 && < 2.3,
data-default-class >= 0.0.1 && < 0.2,
scotty >= 0.10 && < 0.13,
scotty >= 0.10 && < 0.21,
stm >= 2.2 && < 2.6,
text >= 0.11.3.1 && < 2.2,
wai-middleware-static >= 0.8 && < 0.10,
Expand Down
5 changes: 4 additions & 1 deletion kansas-comet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ Library
base >= 4.6 && < 4.20,
containers >= 0.4 && < 0.8,
data-default-class >= 0.0.1 && < 0.2,
scotty >= 0.10 && < 0.13,
-- TODO: Eventually, we should bump the lower version
-- bounds to >=0.20 so that we can remove some CPP in
-- Web.Scotty.Comet.
scotty >= 0.10 && < 0.21,
stm >= 2.2 && < 2.6,
text >= 0.11.3.1 && < 2.2,
time >= 1.2 && < 1.13,
Expand Down

0 comments on commit 70ff635

Please sign in to comment.