import { NestFactory } from '@nestjs/core'; import * as rateLimit from 'express-rate-limit'; import { AppModule } from './app.module'; /* Main.ts starts the server. */ // due to a bug with newest release of express-rate-limit, call for rateLimit is broken // (rateLimit as any) works as a workaround for now // see https://github.com/nfriedly/express-rate-limit/issues/138 const limiter = (rateLimit as any)({ windowMs: 60 * 1000, // one minute max: 100, // limit each IP to 100 requests per windowMs }); async function bootstrap() { const app = await NestFactory.create(AppModule); // Cors is needed for application/json POST app.enableCors(); // apply limiter to all routes app.use(limiter); await app.listen(5000); } bootstrap();