Skip to content
Merged
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
18 changes: 18 additions & 0 deletions docs/guide/rule-engines/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ r.host === 'facebook.com' ? {deny_message: 'Social media blocked'} : true
({allow: {max_tx_bytes: 1024}})
```

## Using Return Statements

JavaScript rules don't allow naked `return` statements. To use returns, wrap your code in an IIFE:

```javascript
(function() {
if (r.host === 'github.com') {
return true;
}

if (r.host.match(/facebook|twitter/)) {
return {deny_message: "Blocked"};
}

return false;
})();
```

## Common Patterns

### Domain Allowlisting
Expand Down
Loading