Skip to content
This repository has been archived by the owner on Nov 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #80 from ozkanonur/test
Browse files Browse the repository at this point in the history
v3.0.0
  • Loading branch information
onur-ozkan authored Sep 12, 2021
2 parents 576380a + c6e22ff commit 8abd8c4
Show file tree
Hide file tree
Showing 76 changed files with 103 additions and 15,322 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test with Jest

on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build
- run: npm run test
env:
CI: true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# vim
*.swp
*.*~

# dependencies
/node_modules

Expand Down
47 changes: 23 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<h2 align="center">Rate Limiter Module for NestJS</h2>

<p align="center">
<a href="https://www.codefactor.io/repository/github/ozkanonur/nestjs-rate-limiter"><img src="https://www.codefactor.io/repository/github/ozkanonur/nestjs-rate-limiter/badge?style=flat-square&sanitize=true" alt="Code Quality" /></a>
<a href="https://www.npmjs.com/package/nestjs-rate-limiter"><img src="https://img.shields.io/npm/v/nestjs-rate-limiter.svg?style=flat-square&sanitize=true" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/package/nestjs-rate-limiter"><img src="https://img.shields.io/npm/dm/nestjs-rate-limiter.svg?style=flat-square&sanitize=true" alt="NPM Downloads" /></a>
<a href="#"><img src="https://img.shields.io/npm/l/nestjs-rate-limiter.svg?colorB=black&label=LICENSE&style=flat-square&sanitize=true" alt="License"/></a>
<a href="https://www.codefactor.io/repository/github/ozkanonur/nestjs-rate-limiter"><img src="https://www.codefactor.io/repository/github/ozkanonur/nestjs-rate-limiter/badge?sanitize=true" alt="Code Quality" /></a>
<a href="https://www.npmjs.com/package/nestjs-rate-limiter"><img src="https://img.shields.io/npm/v/nestjs-rate-limiter.svg?sanitize=true" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/package/nestjs-rate-limiter"><img src="https://img.shields.io/npm/dm/nestjs-rate-limiter.svg?sanitize=true" alt="NPM Downloads" /></a>
<a href="#"><img src="https://img.shields.io/npm/l/nestjs-rate-limiter.svg?colorB=black&label=LICENSE&sanitize=true" alt="License"/></a>
<a href="#"><img src="https://github.com/ozkanonur/nestjs-rate-limiter/actions/workflows/test.yml/badge.svg?branch=master" alt="Test"/></a>

</p>

Expand All @@ -17,7 +18,7 @@
- [Installation](https://github.com/ozkanonur/nestjs-rate-limiter#installation)
- [Basic Usage](https://github.com/ozkanonur/nestjs-rate-limiter#basic-usage)
- [Include Module](https://github.com/ozkanonur/nestjs-rate-limiter#include-module)
- [Using Interceptor](https://github.com/ozkanonur/nestjs-rate-limiter#using-interceptor)
- [Using Guard](https://github.com/ozkanonur/nestjs-rate-limiter#using-guard)
- [With Decorator](https://github.com/ozkanonur/nestjs-rate-limiter#with-decorator)
- [With All Options](https://github.com/ozkanonur/nestjs-rate-limiter#with-all-options)
- [Fastify based Graphql](https://github.com/ozkanonur/nestjs-rate-limiter#fastify-based-graphql)
Expand Down Expand Up @@ -50,7 +51,6 @@
- [customResponseSchema](https://github.com/ozkanonur/nestjs-rate-limiter#-customResponseSchema)
- [Benchmarks](https://github.com/ozkanonur/nestjs-rate-limiter#benchmarks)
- [TODO List](https://github.com/ozkanonur/nestjs-rate-limiter#todo)
- [Examples](https://github.com/ozkanonur/nestjs-rate-limiter/examples/README.md)

# Description

Expand Down Expand Up @@ -83,44 +83,44 @@ First you need to import this module into your main application module:
> app.module.ts
```ts
import { RateLimiterModule } from 'nestjs-rate-limiter';
import { RateLimiterModule } from 'nestjs-rate-limiter'

@Module({
imports: [RateLimiterModule],
})
export class ApplicationModule {}
```

### Using Interceptor
### Using Guard

Now you need to register the interceptor. You can do this only on some routes:
Now you need to register the guard. You can do this only on some routes:

> app.controller.ts
```ts
import { RateLimiterInterceptor } from 'nestjs-rate-limiter';
import { RateLimiterGuard } from 'nestjs-rate-limiter'

@UseInterceptors(RateLimiterInterceptor)
@UseGuards(RateLimiterGuard)
@Get('/login')
public async login() {
console.log('hello');
console.log('hello')
}
```

Or you can choose to register the interceptor globally:
Or you can choose to register the guard globally:

> app.module.ts
```ts
import { APP_INTERCEPTOR } from '@nestjs/core';
import { RateLimiterModule, RateLimiterInterceptor } from 'nestjs-rate-limiter';
import { APP_GUARD } from '@nestjs/core'
import { RateLimiterModule, RateLimiterGuard } from 'nestjs-rate-limiter'

@Module({
imports: [RateLimiterModule],
providers: [
{
provide: APP_INTERCEPTOR,
useClass: RateLimiterInterceptor,
provide: APP_GUARD,
useClass: RateLimiterGuard,
},
],
})
Expand All @@ -135,19 +135,19 @@ route basis:
> app.controller.ts
```ts
import { RateLimit } from 'nestjs-rate-limiter';
import { RateLimit } from 'nestjs-rate-limiter'

@RateLimit({ keyPrefix: 'sign-up', points: 1, duration: 60, errorMessage: 'Accounts cannot be created more than once in per minute' })
@Get('/signup')
public async signUp() {
console.log('hello');
console.log('hello')
}
```

### Dynamic Keyprefix

```ts
import { RateLimit } from 'nestjs-rate-limiter';
import { RateLimit } from 'nestjs-rate-limiter'

@RateLimit({
keyPrefix: () => programmaticFuncThatReturnsValue(),
Expand All @@ -157,7 +157,7 @@ import { RateLimit } from 'nestjs-rate-limiter';
})
@Get('/example')
public async example() {
console.log('hello');
console.log('hello')
}
```

Expand Down Expand Up @@ -201,8 +201,8 @@ The usage of the limiter options is as in the code block below. For an explanati
],
providers: [
{
provide: APP_INTERCEPTOR,
useClass: RateLimiterInterceptor,
provide: APP_GUARD,
useClass: RateLimiterGuard,
},
],
})
Expand Down Expand Up @@ -486,4 +486,3 @@ GraphQLModule.forRoot({
## TODO
- [ ] Support Websocket
- [ ] Support Rpc
- [ ] Github Actions
13 changes: 0 additions & 13 deletions examples/.editorconfig

This file was deleted.

33 changes: 0 additions & 33 deletions examples/.eslintrc.json

This file was deleted.

40 changes: 0 additions & 40 deletions examples/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions examples/.prettierignore

This file was deleted.

3 changes: 0 additions & 3 deletions examples/.prettierrc

This file was deleted.

73 changes: 0 additions & 73 deletions examples/README.md

This file was deleted.

Empty file removed examples/apps/.gitkeep
Empty file.
1 change: 0 additions & 1 deletion examples/apps/rate-limiter-express-app/.eslintrc.json

This file was deleted.

14 changes: 0 additions & 14 deletions examples/apps/rate-limiter-express-app/jest.config.js

This file was deleted.

Empty file.
28 changes: 0 additions & 28 deletions examples/apps/rate-limiter-express-app/src/app/app.module.ts

This file was deleted.

Loading

0 comments on commit 8abd8c4

Please sign in to comment.