Skip to content

Commit

Permalink
Merge branch 'dev' into dev-fe
Browse files Browse the repository at this point in the history
  • Loading branch information
baegyeong authored Nov 28, 2024
2 parents 852ba5c + 5ac11cc commit c710526
Show file tree
Hide file tree
Showing 135 changed files with 9,266 additions and 88 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/close-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Close Related Issue on Merge

on:
pull_request:
types: [closed]
branches: [dev-be, dev-fe]

jobs:
close-issues:
runs-on: ubuntu-latest

steps:
- name: Close related issue
if: ${{ github.event.pull_request.merged == true }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ISSUE_NUMBERS=$(echo "${{ github.event.pull_request.body }}" | grep -o -E '([cC]lose #[0-9]+)' | grep -o '[0-9]\+')
for ISSUE_NUMBER in $ISSUE_NUMBERS; do
echo "Closing issue #$ISSUE_NUMBER"
curl -X PATCH -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER \
-d '{"state": "closed"}'
done
65 changes: 65 additions & 0 deletions .github/workflows/deploy-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Deploy Backend in Monorepo

on:
push:
branches:
- dev-be

jobs:
build-and-deploy:
runs-on: ubuntu-latest

services:
docker:
image: docker:20.10.7
options: --privileged

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache Yarn dependencies
uses: actions/cache@v3
with:
path: |
**/node_modules
~/.yarn-cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build backend
run: |
yarn workspace backend build
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push backend Docker image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/backend:latest -f packages/backend/Dockerfile .
docker push ${{ secrets.DOCKER_USERNAME }}/backend:latest
- name: Deploy to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY}}
port: ${{ secrets.SERVER_PORT }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/backend:latest
docker-compose down
docker-compose up -d
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ pids
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# vscode setting
.vscode

# remote
.remote
Empty file modified .husky/commit-msg
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion .husky/pre-commit
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx eslint --fix
npx eslint --fix
4 changes: 4 additions & 0 deletions packages/backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ pids

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# backup file
.backup
.bak
12 changes: 12 additions & 0 deletions packages/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:20-alpine
WORKDIR /packages
COPY . .
RUN yarn install --frozen-lockfile
RUN yarn workspace backend build

# 한국 시간에 맞춰 변경
RUN apk add --no-cache tzdata
RUN cp /usr/share/zoneinfo/Asia/Seoul /etc/localtime && echo "Asia/Seoul" > /etc/timezone

EXPOSE 3000
CMD ["yarn", "workspace", "backend", "start:prod"]
41 changes: 37 additions & 4 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,61 @@
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"start:prod": "node ../../dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test:e2e": "jest --config ./test/jest-e2e.json",
"mem": "node ../../dist/main --inspect"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.3.0",
"@nestjs/core": "^10.0.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-socket.io": "^10.4.8",
"@nestjs/schedule": "^4.1.1",
"@nestjs/swagger": "^8.0.5",
"@nestjs/typeorm": "^10.0.2",
"@nestjs/websockets": "^10.4.8",
"axios": "^1.7.7",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"dotenv": "^16.4.5",
"express-session": "^1.18.1",
"mysql2": "^3.11.4",
"nest-winston": "^1.9.7",
"passport": "^0.7.0",
"passport-google-oauth20": "^2.0.0",
"passport-local": "^1.0.0",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1"
"rxjs": "^7.8.1",
"socket.io": "^4.8.1",
"typeorm": "^0.3.20",
"unzipper": "^0.12.3",
"winston": "^3.17.0",
"winston-daily-rotate-file": "^5.0.0",
"ws": "^8.18.0"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^5.0.0",
"@types/express-session": "^1.18.0",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/passport-google-oauth20": "^2.0.16",
"@types/passport-local": "^1.0.38",
"@types/supertest": "^6.0.0",
"@types/unzipper": "^0.10.10",
"@types/ws": "^8.5.13",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"cz-emoji-conventional": "^1.1.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
Expand All @@ -62,6 +92,9 @@
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"testEnvironment": "node",
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/$1"
}
}
}
22 changes: 0 additions & 22 deletions packages/backend/src/app.controller.spec.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/backend/src/app.controller.ts

This file was deleted.

39 changes: 34 additions & 5 deletions packages/backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule } from '@nestjs/config';
import { ScheduleModule } from '@nestjs/schedule';
import { TypeOrmModule } from '@nestjs/typeorm';
import { WinstonModule } from 'nest-winston';
import { ScraperModule } from './scraper/scraper.module';
import { AuthModule } from '@/auth/auth.module';
import { SessionModule } from '@/auth/session.module';
import { ChatModule } from '@/chat/chat.module';
import {
typeormDevelopConfig,
typeormProductConfig,
} from '@/configs/typeormConfig';
import { logger } from '@/configs/logger.config';
import { StockModule } from '@/stock/stock.module';
import { UserModule } from '@/user/user.module';

@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
imports: [
ConfigModule.forRoot({ cache: true, isGlobal: true }),
ScheduleModule.forRoot(),
ScraperModule,
StockModule,
UserModule,
TypeOrmModule.forRoot(
process.env.NODE_ENV === 'production'
? typeormProductConfig
: typeormDevelopConfig,
),
WinstonModule.forRoot(logger),
AuthModule,
ChatModule,
SessionModule,
ScraperModule,
],
controllers: [],
providers: [],
})
export class AppModule {}
8 changes: 0 additions & 8 deletions packages/backend/src/app.service.ts

This file was deleted.

54 changes: 54 additions & 0 deletions packages/backend/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Controller, Get, Post, Req, Res } from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { Request, Response } from 'express';
import { sessionConfig } from '@/configs/session.config';
import { User } from '@/user/domain/user.entity';

@ApiTags('Auth')
@Controller('auth')
export class AuthController {
@ApiOperation({
summary: '로그아웃',
description: '로그아웃을 진행한다.',
})
@Post('/logout')
logout(@Req() req: Request, @Res() res: Response) {
req.logout((err) => {
if (err) {
return res
.status(500)
.send({ message: 'Failed to logout', error: err });
}
req.session.destroy((destroyErr) => {
if (destroyErr) {
return res
.status(500)
.send({ message: 'Failed to destroy session', error: destroyErr });
}
res.clearCookie(sessionConfig.name || 'connect.sid');
return res.status(200).send({ message: 'Logged out successfully' });
});
});
}

@ApiOperation({
summary: '로그인 상태 확인',
description: '로그인 상태를 확인합니다.',
})
@ApiOkResponse({
description: '로그인된 상태',
example: { message: 'Authenticated' },
})
@Get('/status')
async user(@Req() request: Request) {
if (request.user) {
const user = request.user as User;
return {
message: 'Authenticated',
nickname: user.nickname,
subName: user.subName,
};
}
return { message: 'Not Authenticated', nickname: null, subName: null };
}
}
24 changes: 24 additions & 0 deletions packages/backend/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Module } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { GoogleAuthController } from '@/auth/google/googleAuth.controller';
import { GoogleAuthService } from '@/auth/google/googleAuth.service';
import { GoogleStrategy } from '@/auth/google/strategy/google.strategy';
import { AuthController } from '@/auth/auth.controller';
import { SessionSerializer } from '@/auth/session/session.serializer';
import { TesterStrategy } from '@/auth/tester/strategy/tester.strategy';
import { TesterAuthController } from '@/auth/tester/testerAuth.controller';
import { TesterAuthService } from '@/auth/tester/testerAuth.service';
import { UserModule } from '@/user/user.module';

@Module({
imports: [UserModule, PassportModule.register({ session: true })],
controllers: [GoogleAuthController, TesterAuthController, AuthController],
providers: [
GoogleStrategy,
GoogleAuthService,
SessionSerializer,
TesterAuthService,
TesterStrategy,
],
})
export class AuthModule {}
Loading

0 comments on commit c710526

Please sign in to comment.