kwhitley / itty-router

A little router.
MIT License
1.7k stars 77 forks source link

How to make a websocket response? #164

Closed kschniedergers closed 1 year ago

kschniedergers commented 1 year ago

I'm making a cloudflare worker that needs to handle websockets, and I'm running into an issue where my router complains when i return a response with a 101 code, which is what should be returned for a websocket connection, as it only wants codes between 200 and 599. I noticed there is a websocket.ts inside src/ but I can't seem to find a way to import it into my project.

My project is also using ts if that is important

kwhitley commented 1 year ago

I'll def take a look at that tonight... I was originally holding back on the websocket implementation to give it more time, but I've def successfully hooked it up both directly to the Worker (from a client), and through a Worker to a DO as well. What exactly is the error you’re seeing? Have some code for me to check out? Def happy to see if I can help ya debug!

kschniedergers commented 1 year ago

My bad, fixed it! I was getting a an "Uncaught RangeError: Responses may only be constructed with status codes in the range 200 to 599, inclusive." but i think i was just messed something up while setting up the routing involving multiple files. Works fine now!