diff --git a/package.json b/package.json index e8a34e7..497e560 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@nestjs/mongoose": "^7.2.4", "@nestjs/platform-express": "^7.5.1", "@nestjs/swagger": "^4.8.0", + "@nestjs/throttler": "^1.1.4", "cache-manager": "^3.4.3", "class-transformer": "^0.4.0", "class-validator": "^0.13.1", diff --git a/src/app.module.ts b/src/app.module.ts index 6b700a4..612b95d 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -6,6 +6,8 @@ import { UserModule } from './user/user.module' import { ApiModule } from './api/api.module' import { LocationModule } from './location/location.module' import { MongooseModule } from '@nestjs/mongoose' +import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler' +import { APP_GUARD } from '@nestjs/core' @Module({ imports: [ @@ -17,11 +19,21 @@ import { MongooseModule } from '@nestjs/mongoose' useNewUrlParser: true, useUnifiedTopology: true, }), + ThrottlerModule.forRoot({ + ttl: 5, + limit: 20, + }), UserModule, ApiModule, LocationModule, ], controllers: [AppController], - providers: [AppService], + providers: [ + AppService, + { + provide: APP_GUARD, + useClass: ThrottlerGuard, + }, + ], }) export class AppModule {} diff --git a/yarn.lock b/yarn.lock index 9f166cb..12847dc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -668,6 +668,13 @@ optional "0.1.4" tslib "2.2.0" +"@nestjs/throttler@^1.1.4": + version "1.1.4" + resolved "https://registry.yarnpkg.com/@nestjs/throttler/-/throttler-1.1.4.tgz#27afbb3d1b8bbcebacf37ace334c72dc20215dca" + integrity sha512-4ewtIx+pREVzhvvhSam+Zdbm6mr8Vo81MC4a1ETj4Aql+61VTjJ7avT2PBjMb0wwcdju9N7OTrUGST8hRkvnZA== + dependencies: + md5 "^2.2.1" + "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" @@ -1710,6 +1717,11 @@ chardet@^0.7.0: resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e" integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== +charenc@0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667" + integrity sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc= + chokidar@3.5.1, chokidar@^3.4.2: version "3.5.1" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.1.tgz#ee9ce7bbebd2b79f49f304799d5468e31e14e68a" @@ -1987,6 +1999,11 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2: shebang-command "^2.0.0" which "^2.0.1" +crypt@0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b" + integrity sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs= + cssom@^0.4.4: version "0.4.4" resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.4.4.tgz#5a66cf93d2d0b661d80bf6a44fb65f5c2e4e0a10" @@ -3123,7 +3140,7 @@ is-binary-path@~2.1.0: dependencies: binary-extensions "^2.0.0" -is-buffer@^1.1.5: +is-buffer@^1.1.5, is-buffer@~1.1.6: version "1.1.6" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w== @@ -4090,6 +4107,15 @@ map-visit@^1.0.0: dependencies: object-visit "^1.0.0" +md5@^2.2.1: + version "2.3.0" + resolved "https://registry.yarnpkg.com/md5/-/md5-2.3.0.tgz#c3da9a6aae3a30b46b7b0c349b87b110dc3bda4f" + integrity sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g== + dependencies: + charenc "0.0.2" + crypt "0.0.2" + is-buffer "~1.1.6" + media-typer@0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"