Skip to content

Commit

Permalink
Merge pull request #29 from Gosrock/dev
Browse files Browse the repository at this point in the history
�문자 발송, 과도한 요청 방지 옵션 추가 배포 테스트
  • Loading branch information
ImNM authored Jul 19, 2022
2 parents 2a58298 + c4156bd commit 4dacd78
Show file tree
Hide file tree
Showing 24 changed files with 496 additions and 16 deletions.
115 changes: 114 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "cross-env NODE_ENV=dev nest start",
"start": "cross-env NODE_ENV=prod nest start",
"start:dev": "cross-env NODE_ENV=dev nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "cross-env NODE_ENV=prod node dist/main",
Expand All @@ -33,14 +33,17 @@
"@nestjs/platform-express": "^8.0.0",
"@nestjs/platform-socket.io": "^8.4.7",
"@nestjs/swagger": "^5.0.9",
"@nestjs/throttler": "^3.0.0",
"@nestjs/typeorm": "^8.1.4",
"@nestjs/websockets": "^8.4.7",
"@redis/client": "^1.2.0",
"@types/crypto-js": "^4.1.1",
"axios": "^0.27.2",
"bull": "^4.8.4",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"cross-env": "^7.0.3",
"crypto-js": "^4.1.1",
"express-basic-auth": "^1.2.1",
"joi": "^17.6.0",
"jsonwebtoken": "^8.5.1",
Expand All @@ -55,6 +58,7 @@
"rxjs": "^7.2.0",
"swagger-ui-express": "^4.4.0",
"typeorm": "^0.3.7",
"uuid": "^8.3.2",
"winston": "^3.8.1"
},
"lint-staged": {
Expand All @@ -72,6 +76,7 @@
"@types/jsonwebtoken": "^8.5.8",
"@types/node": "^16.0.0",
"@types/supertest": "^2.0.11",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"codecov": "^3.8.3",
Expand Down
15 changes: 13 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { AllExceptionsFilter } from './common/exceptions/http-exception.filter';
import { APP_FILTER } from '@nestjs/core';
import { DatabaseModule } from './database/database.module';
import { UsersModule } from './users/users.module';
import { SmsModule } from './sms/sms.module';
import { ThrottlerModule } from '@nestjs/throttler';

@Module({
imports: [
Expand All @@ -34,7 +36,11 @@ import { UsersModule } from './users/users.module';
POSTGRES_PORT: Joi.number().default(5432),
POSTGRES_USER: Joi.string().default('gosrock'),
POSTGRES_PASSWORD: Joi.string().default('gosrock22th'),
POSTGRES_DB: Joi.string().default('ticket')
POSTGRES_DB: Joi.string().default('ticket'),
NAVER_SERVICE_ID: Joi.string(),
NAVER_ACCESS_KEY: Joi.string(),
NAVER_SECRET_KEY: Joi.string(),
NAVER_CALLER: Joi.string()
})
}),
BullModule.forRootAsync({
Expand All @@ -60,7 +66,12 @@ import { UsersModule } from './users/users.module';
SlackModule,
SocketModule,
DatabaseModule.forRoot({ isTest: false }),
UsersModule
UsersModule,
SmsModule,
ThrottlerModule.forRoot({
ttl: process.env.NODE_ENV === 'prod' ? 300 : 60,
limit: 3
})
],

providers: [
Expand Down
11 changes: 11 additions & 0 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,25 @@ import { ResponseRequestValidationDto } from './dtos/RequestValidation.response.
import { RequestValidateNumberDto } from './dtos/ValidateNumber.request.dto';
import { ResponseValidateNumberDto } from './dtos/ValidateNumber.response.dto';
import { RegisterTokenGuard } from './guards/RegisterToken.guard';
import { ThrottlerBehindProxyGuard } from './guards/TrottlerBehindProxy.guard';

@ApiTags('auth')
@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}

@UseGuards(ThrottlerBehindProxyGuard)
@ApiOperation({ summary: '휴대전화번호 인증번호를 요청한다.' })
@ApiBody({ type: RequestPhoneNumberDto })
@ApiResponse({
status: 200,
description: '요청 성공시',
type: ResponseRequestValidationDto
})
@ApiResponse({
status: 429,
description: '과도한 요청을 보낼시에'
})
@Post('message/send')
async requestPhoneValidationNumber(
@Body() requestPhoneNumberDto: RequestPhoneNumberDto
Expand Down Expand Up @@ -82,6 +88,7 @@ export class AuthController {
);
}

@UseGuards(ThrottlerBehindProxyGuard)
@ApiOperation({ summary: '슬랙 인증번호를 발송한다 (관리자 용 )' })
@ApiResponse({
status: 200,
Expand All @@ -92,6 +99,10 @@ export class AuthController {
status: 400,
description: '슬랙에 들어와있는 유저가 아닐때 , 어드민 유저가 아닐 때'
})
@ApiResponse({
status: 429,
description: '과도한 요청을 보낼시에'
})
@ApiBody({ type: RequestAdminSendValidationNumberDto })
@Post('/slack/send')
async slackSendValidationNumber(
Expand Down
8 changes: 8 additions & 0 deletions src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { User } from 'src/database/entities/user.entity';
import { UserRepository } from 'src/database/repositories/user.repository';
import { RedisModule } from 'src/redis/redis.module';
import { SlackModule } from 'src/slack/slack.module';
import { SmsModule } from 'src/sms/sms.module';
import { UsersModule } from 'src/users/users.module';
import { UsersService } from 'src/users/users.service';
import { AuthController } from './auth.controller';
Expand All @@ -14,6 +15,13 @@ import { RegisterTokenGuard } from './guards/RegisterToken.guard';

@Module({
imports: [
SmsModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
isProd: configService.get('NODE_ENV') === 'prod' ? true : false
}),
inject: [ConfigService]
}),
UsersModule,
SlackModule,
TypeOrmModule.forFeature([User]),
Expand Down
Loading

0 comments on commit 4dacd78

Please sign in to comment.