rhinobase / hono-rate-limiter

Rate Limit middleware for Hono Server
https://hono-rate-limiter.vercel.app
MIT License
247 stars 12 forks source link

fix(core): pass the hono context into websocket functions #20

Closed alexgleason closed 3 months ago

alexgleason commented 3 months ago

Since the limiter is defined above the controller, there's not a convenient way to access the Hono context unless we pass it in. I need it in the skip function, but it seems reasonable that it should be passed into the handler as well.

vercel[bot] commented 3 months ago

@alexgleason is attempting to deploy a commit to the rhinobase Team on Vercel.

A member of the Team first needs to authorize it.

alexgleason commented 3 months ago

I'm thinking I might not actually go this path. I keep hitting walls, eg https://github.com/honojs/hono/issues/2997

This file is only like 100 lines of code, and I have added more code than that trying to adapt my existing controllers (which use Deno.upgradeWebsocket) to use Hono's helper, and then fit them into the right shape to call the limiter on it.

Instead I'm thinking I'll create another version that's similar, but it directly wraps a standard WebSocket object (which Deno uses to represent connections on the server side) and add a message event listener to it. Aside from that it will still take a Store and match the conventions of this library.

That being said, I still think this MR is an improvement. So, up to you.