onur-ozkan / nestjs-rate-limiter

Highly configurable and extensible rate limiter library
https://npmjs.com/package/nestjs-rate-limiter
MIT License
238 stars 43 forks source link

Run and debug errors. #2

Closed VaughanWebber closed 4 years ago

VaughanWebber commented 5 years ago

@RyanTheAllmighty I've installed the rate limiter into our NestJS project and get errors when running npm run start:dev and while debugging.

npm run start:dev:

*\node_modules\nestjs-rate-limiter\dist\rate-limiter.decorator.js:4

exports.RateLimit = (options) => common_1.SetMetadata('rateLimit', options);

TypeError: common_1.SetMetadata is not a function

Debugging:

node_modules/nestjs-rate-limiter/dist/rate-limiter.interceptor.d.ts:3:45 - error TS2305
'"*/node_modules/@nestjs/common/index"' has no exported member 'CallHandler'.

import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';

app.module.ts:

import { MiddlewareConsumer, Module, NestModule, RequestMethod } from '@nestjs/common';

import { RateLimiterModule } from 'nestjs-rate-limiter';
import { FrontendMiddleware } from './middleware/frontend.middleware';

@Module({
    imports: [
        RateLimiterModule,
    ],
})
export class AppModule implements NestModule {
    public configure(consumer: MiddlewareConsumer): void {
        consumer.apply(FrontendMiddleware).forRoutes(
            {
                path: '/**', // For all routes
                method: RequestMethod.ALL, // For all methods
            },
        );
    }
}

Controller:

import { Controller, Post, UseInterceptors } from '@nestjs/common';
import { RateLimit, RateLimiterInterceptor } from 'nestjs-rate-limiter';

@UseInterceptors(RateLimiterInterceptor)
@Controller('api/user/login')
export class LoginController {

    @RateLimit({ points: 1, duration: 60 })
    @Post()
    public async create(
    ): Promise<any> {
        return;
    }
}
MattInternet commented 4 years ago

I am also getting common_1.SetMetadata is not a function

VaughanWebber commented 4 years ago

@MattInternet unfortunately I'm still waiting on a response.

maayoko commented 4 years ago

Make sure you have installed nest.js version that includes this file https://github.com/nestjs/nest/blob/master/packages/common/decorators/core/set-metadata.decorator.ts.

If you go with the latest, you should be fine.

RyanTheAllmighty commented 4 years ago

What version of NestJS are you using? It should be fine on all 6.x versions

VaughanWebber commented 4 years ago

@RyanTheAllmighty 6.8.3, but I have just been doing console.log as I needed to continue working. Had to stop using the Debugger. Fired it up the debugger again now and getting other errors so I'll have to figure those out to see if this error still exists.

onur-ozkan commented 4 years ago

Closed due to inactivity. Feel free to re-open if this happens on v2.