on master help sign in
ob run: Handle application websocket requests

Workaround jsaddleOr wanting to handle all websockets requests without having a chance for run to proxy non jsaddle websocket requests to the backend. This assumes that websocket requests to "/" are meant for jsaddle which is what the current version pinned by reflex-platform uses.

commit902988915e01a7b6d84220a2ac794a8a7782983b authorLuigy Leon <luigy@outlook.com> dateTue 12 Jun 2018, 09:36 (8 years ago) parentca19585
2 files changed+10−1
lib/run/obelisk-run.cabal+1 lib/run/src/Obelisk/Run.hs+9−1
lib/run/obelisk-run.cabal+1
@@ -24,6 +24,7 @@ library
2424 , streaming-commons
2525 , text
2626 , wai
27+ , wai-websockets
2728 , warp
2829 , websockets
2930 exposed-modules:
lib/run/src/Obelisk/Run.hs+9−1
@@ -25,6 +25,7 @@ import Network.Wai (Application)
2525import qualified Network.Wai as W
2626import Network.Wai.Handler.Warp
2727import Network.Wai.Handler.Warp.Internal (settingsHost, settingsPort)
28+import Network.Wai.Handler.WebSockets (isWebSocketsReq)
2829import Network.WebSockets (ConnectionOptions)
2930import Network.WebSockets.Connection (defaultConnectionOptions)
3031import Obelisk.ExecutableConfig (get)
@@ -80,10 +81,17 @@ obeliskApp :: ConnectionOptions -> StaticWidget () () -> Widget () () -> Applica
8081obeliskApp opts h b backend = do
8182 html <- BSLC.fromStrict <$> indexHtml h
8283 let entryPoint = mainWidget' b >> syncPoint
83− jsaddleOr opts entryPoint $ \req sendResponse -> case (W.requestMethod req, W.pathInfo req) of
84+ jsaddle <- jsaddleOr opts entryPoint $ \req sendResponse -> case (W.requestMethod req, W.pathInfo req) of
8485 ("GET", []) -> sendResponse $ W.responseLBS H.status200 [("Content-Type", "text/html")] html
8586 ("GET", ["jsaddle.js"]) -> sendResponse $ W.responseLBS H.status200 [("Content-Type", "application/javascript")] $ jsaddleJs False
8687 _ -> backend req sendResponse
88+ -- Workaround jsaddleOr wanting to handle all websockets requests without
89+ -- having a chance for run to proxy non jsaddle websocket requests to the
90+ -- backend.
91+ return $ \req sendResponse -> do
92+ if isWebSocketsReq req && not (null $ W.pathInfo req)
93+ then backend req sendResponse
94+ else jsaddle req sendResponse
8795
8896indexHtml :: StaticWidget () () -> IO ByteString
8997indexHtml h = do