Skip to content

v2.12.0 - Fanout

Compare
Choose a tag to compare
@AndrewBarba AndrewBarba released this 08 Feb 23:11
· 25 commits to main since this release
4b9b48e
  • Integrates Fanout into request and response handling
  • Adds a new FanoutClient for publishing messages to Fanout channels
  • Switches underlying crypto lib to apple/swift-crypto
  • Adds support for creating and verifying ECDSA style JWTs (ex. ES256)
// Clients connect here
router.get("/stream") { req, res in
    guard req.isUpgradeWebsocketRequest() else {
        return try await res.status(400).send("Invalid websocket request")
    }
    try req.upgradeWebsocket(to: .fanout, hostname: "localhost")
}

// Fanout relays messages here
router.post("/stream") { req, res in
    let message = try await req.fanoutMessage()
    if message.event == .open {
        return try await res.send(fanout: .open, .subscribe(to: "test"))
    }
    try await res.send(fanout: .ack)
}

// Authenticated publish endpoint here
router.post("/message") { req, res in
    let token = try ConfigStore(name: "env")["fanout_token"]!
    let client = FanoutClient(token: token)
    let content = try await req.body.text()
    let data = try await client.publish(content, to: "test")
    try await res.proxy(data)
}