-
Hello, I'm planning to create a Cloudflare worker using Rust instead of TypeScript, but I'm unsure if the crate I'm considering will meet my needs. I have no prior experience building Cloudflare workers. The worker will act as middleware between a client and another server. It won't just be a reverse proxy; it will process data and send different information to a downstream server that isn't accessible from the Internet. Both connections (client-worker and worker-server) will use WebSockets, so the worker must function as both a WebSockets server and client. I also want to use the rate limiting binding to mitigate client abuse. Could someone provide guidance on achieving this with the crate? I believe I can use a standard WebSockets client from crates.io, but I'm unsure how to implement a WebSockets server and integrate the rate limiting binding. Thanks, Gus. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I haven't tried the rate limiting api myself and I don't know if the support was already added. But most support is done in the JS/TS side, you might miss a rust wrapper, that you can easily do, normally there is similar code already for other stuff. Workers use a specific WebSockets api that is specially relevant for the server handling of websockets, as it allows it to hibernate, instead of have the code constantly running. |
Beta Was this translation helpful? Give feedback.
-
Thanks @spigaz! I just took a look at the code, and even though it's not mentioned on the README, there's an implementation of the rate limiting functionality and the WS client. It wasn't immediately obvious to me, but that same |
Beta Was this translation helpful? Give feedback.
I haven't tried the rate limiting api myself and I don't know if the support was already added.
But most support is done in the JS/TS side, you might miss a rust wrapper, that you can easily do, normally there is similar code already for other stuff.
Then open a PR and they will accept it.
Workers use a specific WebSockets api that is specially relevant for the server handling of websockets, as it allows it to hibernate, instead of have the code constantly running.
https://developers.cloudflare.com/workers/runtime-apis/websockets/