Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- waiApplication :: Route route => (ByteString -> ByteString) -> (route -> Eff '[Hyperbole, IOE] ()) -> Application
- application :: Route route => (ByteString -> ByteString) -> (route -> Eff '[Hyperbole, IOE] ()) -> Application
- websocketsOr :: ConnectionOptions -> ServerApp -> Application -> Application
Documentation
waiApplication :: Route route => (ByteString -> ByteString) -> (route -> Eff '[Hyperbole, IOE] ()) -> Application Source #
application :: Route route => (ByteString -> ByteString) -> (route -> Eff '[Hyperbole, IOE] ()) -> Application Source #
Start both a websockets and a WAI server. Wai app serves initial pages, and attempt to process actions via sockets If the socket connection is unavailable, will fall back to the WAI app to process actions
websocketsOr :: ConnectionOptions -> ServerApp -> Application -> Application #
Upgrade a websockets
ServerApp
to a wai
Application
. Uses
the given backup Application
to handle Request
s that are not
WebSocket requests.
websocketsOr opts ws_app backup_app = \req respond -> casewebsocketsApp
opts ws_app req ofNothing
-> backup_app req send_responseJust
res -> respond res
For example, below is an Application
that sends "Hello, client!"
to
each connected client.
app ::Application
app =websocketsOr
defaultConnectionOptions
wsApp backupApp where wsApp ::ServerApp
wsApp pending_conn = do conn <-acceptRequest
pending_connsendTextData
conn ("Hello, client!" ::Text
) backupApp ::Application
backupApp _ respond = respond $responseLBS
status400
[] "Not a WebSocket request"