Upgrade a websockets ServerApp to a wai Application. Uses
the given backup Application to handle Requests that are not
WebSocket requests.
websocketsOr opts ws_app backup_app = \req respond ->
case websocketsApp opts ws_app req of
Nothing -> backup_app req send_response
Just 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_conn
sendTextData conn ("Hello, client!" :: Text)
backupApp :: Application
backupApp _ respond = respond $ responseLBS Network.HTTP.Types.status400 [] "Not a WebSocket request"