summaryrefslogtreecommitdiff
path: root/fig-frontend/src/Fig/Frontend/Utils.hs
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2024-08-04 02:09:37 -0400
committerLLLL Colonq <llll@colonq>2024-08-04 02:09:37 -0400
commit7b101b8c3c0481d76733c77008b5b763ceb3b535 (patch)
treea2a8b3c46f4b6ae87eb288d7834be8b254522da2 /fig-frontend/src/Fig/Frontend/Utils.hs
parent790b517b8e64c46bcd6bb71637d2d0eb68c51abd (diff)
Live monitor endpoint
Diffstat (limited to 'fig-frontend/src/Fig/Frontend/Utils.hs')
-rw-r--r--fig-frontend/src/Fig/Frontend/Utils.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/fig-frontend/src/Fig/Frontend/Utils.hs b/fig-frontend/src/Fig/Frontend/Utils.hs
index 3081ddb..090c6ba 100644
--- a/fig-frontend/src/Fig/Frontend/Utils.hs
+++ b/fig-frontend/src/Fig/Frontend/Utils.hs
@@ -5,12 +5,17 @@ module Fig.Frontend.Utils
( FigFrontendException(..)
, loadConfig
, Config(..)
+ , websocket
, module Network.HTTP.Types.Status
) where
import Fig.Prelude
import Network.HTTP.Types.Status
+import qualified Network.Wai.Handler.WebSockets as Wai.WS
+import qualified Network.WebSockets as WS
+
+import qualified Web.Scotty as Sc
import qualified Toml
@@ -39,3 +44,10 @@ loadConfig :: FilePath -> IO Config
loadConfig path = Toml.decodeFileEither configCodec path >>= \case
Left err -> throwM . FigFrontendException $ tshow err
Right config -> pure config
+
+websocket :: ByteString -> (WS.Connection -> IO ()) -> Sc.ScottyM ()
+websocket pat h = Sc.middleware $ Wai.WS.websocketsOr WS.defaultConnectionOptions handler
+ where
+ handler pending = if WS.requestPath (WS.pendingRequest pending) == pat
+ then WS.acceptRequest pending >>= h
+ else WS.rejectRequest pending ""