From 70ff635adc78a9b88972b8f521d49163107ead2b Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Thu, 5 Oct 2023 05:38:32 -0700 Subject: [PATCH] Support building with scotty-0.20 Fixes #10. --- CHANGELOG.md | 3 +++ Web/Scotty/Comet.hs | 17 ++++++++++++----- example/kansas-comet-example.cabal | 2 +- kansas-comet.cabal | 5 ++++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12309f6..047e8d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/Web/Scotty/Comet.hs b/Web/Scotty/Comet.hs index a00da23..fa5d3a8 100644 --- a/Web/Scotty/Comet.hs +++ b/Web/Scotty/Comet.hs @@ -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 @@ -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 @@ -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 $ @@ -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 @@ -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" diff --git a/example/kansas-comet-example.cabal b/example/kansas-comet-example.cabal index fbda320..babb7bd 100644 --- a/example/kansas-comet-example.cabal +++ b/example/kansas-comet-example.cabal @@ -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, diff --git a/kansas-comet.cabal b/kansas-comet.cabal index 5ef6f08..6931c1f 100644 --- a/kansas-comet.cabal +++ b/kansas-comet.cabal @@ -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,