Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a browser compatible rate limiter #11

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

playfulkittykat
Copy link
Contributor

Noticed I was hitting the rate limit in my web app, so here's an implementation of the rate limiter that works in the browser.

It's in its own crate to keep the dependency tree manageable. If the rate-limit feature is not enabled, no additional dependencies are compiled. On the other hand, if it is enabled, only the platform specific dependencies are compiled. I'm not sure there's a way to mix target.'cfg(...)'.dependencies and features otherwise.

Further investigation is needed to know if the OPTIONS + POST request pattern required by CORS counts as two API requests.

@nasso
Copy link
Owner

nasso commented Oct 24, 2024

i think it should be possible to enable dependencies when a feature is enabled

@playfulkittykat
Copy link
Contributor Author

playfulkittykat commented Oct 25, 2024

You can, yes. Using the feature-name = ["crate"] syntax. I'm just not sure how to mix that with target.cfg(...).dependencies.

I don't want to depend on tokio when compiling for WASM nor on gloo-timers when compiling for x86.

@playfulkittykat
Copy link
Contributor Author

Oh, actually, I just figured it out.

Copy link
Owner

@nasso nasso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the two files have a lot of code in common, they could maybe just be the same file with 2-3 #[cfg(...)] here and there

but if that works for you it looks good to me! thank you for your contributions!

@nasso nasso merged commit 0924c2c into nasso:master Oct 28, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants