Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NDD-254]: 개발용 토큰 반환 API 구현 (0.5h / 0.5h) #106

Merged
merged 6 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/be-cd-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches:
- dev

defaults:
run:
working-directory: ./BE

jobs:
build:
runs-on: self-hosted
Expand All @@ -20,4 +24,4 @@ jobs:
sudo docker build -t ${{secrets.BE_DOCKER_USERNAME}}/${{secrets.BE_DOCKER_REPO}}:${{secrets.DOCKER_DEV_TAG}} --platform linux/amd64 .
sudo docker push ${{secrets.BE_DOCKER_USERNAME}}/${{secrets.BE_DOCKER_REPO}}:${{secrets.DOCKER_DEV_TAG}}
- name: Run Docker Container
run: sudo docker run -d -p 8080:8080 -e TZ=Asia/Seoul --name ${{secrets.BE_DOCKER_CONTAINER}} ${{secrets.BE_DOCKER_USERNAME}}/${{secrets.BE_DOCKER_REPO}}:${{secrets.DOCKER_DEV_TAG}}
run: docker run --oom-kill-disable --restart on-failure -d -p 80:8080 -e TZ=Asia/Seoul --name ${{secrets.BE_DOCKER_CONTAINER}} ${{secrets.BE_DOCKER_USERNAME}}/${{secrets.BE_DOCKER_REPO}}:${{secrets.DOCKER_DEV_TAG}}
3 changes: 3 additions & 0 deletions BE/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { ApiExcludeEndpoint } from '@nestjs/swagger';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
@ApiExcludeEndpoint()
async getHello() {
return this.appService.getHello();
}

@Get('/initializeDummy')
@ApiExcludeEndpoint()
async saveDummy() {
await this.appService.saveDummy();
}
Expand Down
3 changes: 1 addition & 2 deletions BE/src/auth/service/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { CategoryRepository } from '../../category/repository/category.repositor
import { QuestionRepository } from '../../question/repository/question.repository';
import { Category } from '../../category/entity/category';
import { Question } from '../../question/entity/question';

const BEARER_PREFIX: string = 'Bearer ';
import { BEARER_PREFIX } from 'src/constant/constant';

@Injectable()
export class AuthService {
Expand Down
2 changes: 2 additions & 0 deletions BE/src/constant/constant.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dotenv/config';

export const BEARER_PREFIX: string = 'Bearer ';

export const companies = [
'네이버',
'카카오',
Expand Down
4 changes: 4 additions & 0 deletions BE/src/token/service/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export class TokenService {
}
}

async getDevToken() {
return this.createToken(1); // 1번은 developndd 이메일로 가입한 개발자용 회원임
}

private async findByAccessToken(accessToken: string) {
return await this.tokenRepository.findByAccessToken(accessToken);
}
Expand Down
17 changes: 17 additions & 0 deletions BE/src/token/token.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Controller, Get, Res } from '@nestjs/common';
import { TokenService } from './service/token.service';
import { Response } from 'express';
import { BEARER_PREFIX } from 'src/constant/constant';
import { ApiExcludeEndpoint } from '@nestjs/swagger';

@Controller('/api/token')
export class TokenController {
constructor(private tokenService: TokenService) {}

@Get()
@ApiExcludeEndpoint()
async getDevToken(@Res() res: Response) {
const devToken = await this.tokenService.getDevToken();
res.setHeader('Authorization', `${BEARER_PREFIX} ${devToken}`).send();
}
}
2 changes: 2 additions & 0 deletions BE/src/token/token.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';
import 'dotenv/config';
import { AccessTokenStrategy } from './strategy/access.token.strategy';
import { TokenController } from './token.controller';

@Module({
imports: [
Expand All @@ -30,5 +31,6 @@ import { AccessTokenStrategy } from './strategy/access.token.strategy';
AccessTokenStrategy,
],
exports: [TokenService],
controllers: [TokenController],
})
export class TokenModule {}
Loading