【发布时间】:2019-10-14 11:51:10
【问题描述】:
我刚开始实现 API 的 Nest js,我正在使用 Fastify 适配器。 我需要帮助在 Nest JS 中使用 FastifyAdapter 配置速率限制。
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
);
const limiter = fastifyRateLimit(fastify(), {
timeWindow: 15 * 60 * 1000, // 15 minutes
max: 100 // limit each IP to 100 requests per windowMs
}, (err) => {
});
app.use(limiter);
await app.listen(configService.getPort());
}
bootstrap();
请参考以上代码并改正错误
【问题讨论】:
-
你是怎么得到
fastify()的? -
我使用 npm 安装
-
不,在您看到速率限制器的代码中,您有
fastify()但我没有看到fastify在其他任何地方初始化
标签: node.js nestjs rate-limiting fastify nestjs-fastify