Skip to content
This repository was archived by the owner on Oct 24, 2021. It is now read-only.

Add example of how to rate limit per-connection #739

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions source/api/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,19 @@ const loginRule = {
// Add the rule, allowing up to 5 messages every 1000 milliseconds.
DDPRateLimiter.addRule(loginRule, 5, 1000);
```

Here's another example that rate-limits adding a custom `threads.create` method per-connection:
```js
// Define a rule that matches login attempts by non-admin users.
const threadCreateRule = {
type: 'method',
name: 'threads.create',
connectionId() {
return true;
}
};
// Add the rule, allowing up to 5 messages per user connection (i.e., every connection is rate-limited separately) every 30 minutes.
DDPRateLimiter.addRule(threadCreateRule, 5, 1000 * 60 * 30);
```
{% apibox "DDPRateLimiter.removeRule" nested:true instanceDelimiter:. %}
{% apibox "DDPRateLimiter.setErrorMessage" nested:true instanceDelimiter:. %}