Node.js (NestJS)
Requirements
Installation & Configuration
1
2
4
Enable Rate limiting and User blocking
// src/zen.guard.ts
import { Injectable, CanActivate, HttpException, HttpStatus } from "@nestjs/common";
import { shouldBlockRequest } from "@aikidosec/firewall";
@Injectable()
export class ZenGuard implements CanActivate {
canActivate(): boolean {
const result = shouldBlockRequest();
if (result.block) {
if (result.type === "ratelimited") {
throw new HttpException("You are rate limited by Zen.", HttpStatus.TOO_MANY_REQUESTS);
}
if (result.type === "blocked") {
throw new HttpException("You are blocked by Zen.", HttpStatus.FORBIDDEN);
}
}
return true;
}
}// src/main.ts
const app = await NestFactory.create(AppModule);
app.useGlobalGuards(new ZenGuard());5
Setup rate limiting in the dashboard



You are rate limited by Aikido firewall. (Your IP: 1.2.3.4)Last updated
Was this helpful?
