I am building a WebSocket client for Discord’s Gateway API using DOs. Everything works when running locally with --local, but when I remove --local or when I deploy to CF, my WebSocket client (created via new WebSocket()) immediately gets an error event that says:
Failed to establish the WebSocket connection: expected server to reply with HTTP status code 101 (switching protocols), but received 401 instead…
Discord’s Gateway WS protocol doesn’t require any authorization to open the WS connection normally (a token gets passed in a message later), and this exact same code works with wrangler dev --local.
Could there be some difference in how new WebSocket() when deployed to Cloudflare vs when running locally?