WEBSOCKETS

Protect the upgrade before opening a socket

WebSockets can live in endpoint groups, inherit their path and middleware, and add route-specific middleware. Browser clients authenticate the upgrade with a search parameter because they cannot set arbitrary upgrade headers.

dowe
middleware requireSocketToken
  jwt verified secret:env.JWT_SECRET algorithm:"HS256" token:req.query.token
  if verified.valid
    next
  return status:401 json:{ ok:false error:"Unauthorized" }

endpoints controlRoutes
  group path:"/api/v1/sip"
    websocket path:"/control" middleware:[requireSocketToken]
      open ws
        log "sip control websocket open"
      message ws
        ws event source:"json"
        send ws json:{ ok:true channel:"sip-control" }
      close ws
        log "sip control websocket close"
Concern
Rule

No data

There are no records to display