Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
HeeDragoN1123 authored Oct 17, 2023
2 parents 22d30b9 + f40f01e commit 7e99d1c
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 1 deletion.
65 changes: 65 additions & 0 deletions .github/workflows/nest_lm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: nest_lm CI

on:
push:
branches: [ "main" ]

env:
PROJECT_NAME: local_mingle
BUCKET_NAME: s3-bucket-local-mingle
CODE_DEPLOY_APP_NAME: CD-app-local-mingle
DEPLOYMENT_GROUP_NAME: CD-app-group-local-mingle

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present

# S3로 보낼 압축 파일 생성
- name: zip file
run: |
# zip으로 압축파일 생성
# CI.zip은 압축 파일 이름, 나머지는 압축할 코드 파일 또는 폴더를 지정합니다.
# workflow와 동일한 위치의 폴더와 파일을 압축합니다.
zip -qq -r ./$GITHUB_SHA.zip .
# AWS 인증하기
- name: AWS configure credentials
uses: aws-actions/configure-aws-credentials@v1
with:
# 엑세스 키 입력
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# 엑세스 시크릿 키 입력
aws-secret-access-key: ${{ secrets.AWS_PRIVATE_ACCESS_KEY }}
# 지역 설정: 서울
aws-region: ap-northeast-2

# S3로 업로드하기
- name: upload to S3
run: aws s3 cp ./$GITHUB_SHA.zip s3://s3-bucket-local-mingle/local_mingle/$GITHUB_SHA.zip

# codeDeploy 실행
- name: request deploy to codedeploy
run: aws deploy create-deployment
--application-name CD-app-local-mingle
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name CD-app-group-local-mingle
--s3-location bucket=s3-bucket-local-mingle,bundleType=zip,key=local_mingle/$GITHUB_SHA.zip
22 changes: 22 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: 0.0
os: linux

# S3로부터 받은 .zip file의 압축해제 경로 설정
files:
- source: /
destination: /home/ubuntu/LocalMingle-BE
overwrite: yes
file_exists_behavior: OVERWRITE

# 압축해제 된 파일들의 권한 설정
permissions:
- object: /home/ubuntu/LocalMingle-BE
owner: ubuntu
group: ubuntu

# codedeploy가 참조할 스크립트의 경로 설정
hooks:
AfterInstall:
- location: scripts/deploy.sh
timeout: 60
runas: ubuntu
22 changes: 22 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 프로젝트 위치 설정
REPOSITORY=/home/ubuntu/LocalMingle-BE

# 프로젝트 위치로 이동
cd $REPOSITORY

# 의존성 설치
echo "> install dependency"
npm install

# 프로젝트 build
echo "> build application"
nest build

# pm2 실행 또는 리로드
if pm2 list | grep -q "LocalMingle-BE"; then
echo "> reload application"
pm2 reload LocalMingle-BE
else
echo "> start application"
pm2 start dist/src/main.js --name LocalMingle-BE
fi
4 changes: 4 additions & 0 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export class AuthController {
@Req() req: Request,
@Res({ passthrough: true }) res: Response // Response 객체 주입
): Promise<void> {

const { accessToken, refreshToken, userId } = await this.authService.login({

email,
password,
res,
Expand All @@ -65,8 +67,10 @@ export class AuthController {
// 리프레시 토큰을 HTTP 응답 헤더에 추가
res.header('refreshToken', refreshToken);


res.status(200).json({ userId }); // 클라이언트에게 JSON 응답을 보냄


//res.cookie('refreshToken', refreshToken, { httpOnly: true, secure: false });

// 액세스 토큰을 클라이언트에게 JSON 응답으로 반환 (Response body 에 전송)
Expand Down
5 changes: 5 additions & 0 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { JwtService } from '@nestjs/jwt';
import * as bcrypt from 'bcrypt';
//import { IAuthServiceLogin } from './interface/auth-service.interface';
import { UsersService } from 'src/users/users.service';
import { User } from '@prisma/client';

@Injectable()
export class AuthService {
Expand All @@ -21,8 +22,10 @@ export class AuthService {
// 리팩토링 시 res 빼도 작동하는지 테스트
accessToken: string;
refreshToken: string;

//user: User; // User 정보를 반환하기 위한 타입
userId: number; // userId만 반환

}> {
// 1. 이메일이 일치하는 유저를 DB에서 찾기
const user = await this.usersService.findByEmail({ email });
Expand Down Expand Up @@ -53,8 +56,10 @@ export class AuthService {
// res.header('Authorization', `Bearer ${accessToken}`);
// res.header('RefreshToken', refreshToken);


//TODO : user값 대신 userId값만 넘어가게 수정해야함 ()
return { accessToken, refreshToken, userId: user.userId }; //리턴값

}

getAccessToken({ user, res }): string {
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function bootstrap() {

const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);

//cors 정책
app.enableCors({
origin: ['http://localhost:5173'],
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
Expand Down

0 comments on commit 7e99d1c

Please sign in to comment.