fastify

How to configure rate-limit with fastify-adapter in nest js

情到浓时终转凉″ 提交于 2021-02-10 20:34:55
问题 I Just started implementing API's Nest js and I am using Fastify adapter. I need help to configure Rate limit using FastifyAdapter in Nest JS. 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()); }

How to configure rate-limit with fastify-adapter in nest js

我只是一个虾纸丫 提交于 2021-02-10 20:27:27
问题 I Just started implementing API's Nest js and I am using Fastify adapter. I need help to configure Rate limit using FastifyAdapter in Nest JS. 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()); }

How to upload images to fastify + graphql backend with axios?

做~自己de王妃 提交于 2021-01-28 13:35:50
问题 When sending images via axios I found I have to use formdata. I add my images here but when sending the formdata my entire backend just freezes, just says "pending". Ive been following this And my attempt so far: backend: Apollo: import { ApolloServer, makeExecutableSchema } from 'apollo-server-fastify'; const schema = makeExecutableSchema({ typeDefs, resolvers }); const apolloServer = new ApolloServer({ schema, uploads: { maxFileSize: 10000000, maxFiles: 5, }, }); (async function() { app

Fastify & NestJS - How to set response headers in interceptor

淺唱寂寞╮ 提交于 2021-01-28 05:35:02
问题 I'm trying to set the response headers in my interceptor, and have had no luck with any method I've found yet. I've tried: const request = context.switchToHttp().getRequest(); const response = context.switchToHttp().getResponse(); <snippet of code from below> return next.handle(); request.res.headers['my-header'] = 'xyz' response.header('my-header', 'xyz') response.headers['my-header'] = 'xyz' response.header['my-header'] = 'xyz' with no luck. The first option says that res is undefined, the

NestJS set HttpStatus in interceptor

大城市里の小女人 提交于 2020-12-29 07:24:46
问题 I'm using an interceptor to transform my response. I want to set the HttpStatus inside but the code I'm using now doesn't work. import { CallHandler, ExecutionContext, NestInterceptor, SetMetadata } from '@nestjs/common'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { classToPlain } from 'class-transformer'; import { ApiResponse } from '../models/apiResponse'; export class TransformInterceptor implements NestInterceptor { intercept( context: ExecutionContext

How to augment module in project scope?

一个人想着一个人 提交于 2019-12-11 16:48:02
问题 I'm using fastify with plugin fastify-static. I also provide my own TypeScript types declaration for this plugin in typings/fastify-static/index.d.ts : declare module "fastify-static" { import { Plugin } from "fastify"; import { Server, IncomingMessage, ServerResponse } from "http"; namespace fastifyStatic { const instance: Plugin<Server, IncomingMessage, ServerResponse, any>; } export = fastifyStatic.instance } Additionally plugin extends fastify FastifyReply with method sendFile . When I