Skip to content

Commit

Permalink
Merge pull request #129 from 42-world/develop
Browse files Browse the repository at this point in the history
2월 마지막주 main
  • Loading branch information
rockpell authored Feb 27, 2022
2 parents 3a83e23 + e898786 commit 36d2910
Show file tree
Hide file tree
Showing 54 changed files with 903 additions and 219 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ RUN mkdir ft-world

WORKDIR ft-world

COPY ./config ./config
COPY ./src ./src
COPY ./test ./test
COPY ./views ./views
Expand Down
41 changes: 23 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
COMPOSE = sudo docker-compose
COMPOSE_ENV = ${COMPOSE} --env-file config/.env.$(1)
COMPOSE = docker-compose
COMPOSE_ENV = ${COMPOSE} --env-file config/.env

dev: db
dev:
cp ./config/.env.dev ./config/.env
make db redis
yarn start:dev

alpha:
export NODE_ENV=alpha && $(call COMPOSE_ENV,alpha) up --build -d
cp ./config/.env.alpha ./config/.env
export NODE_ENV=alpha && sudo $(call COMPOSE_ENV) up --build -d

prod:
export NODE_ENV=prod && $(call COMPOSE_ENV,prod) up --build -d
cp ./config/.env.prod ./config/.env
make api-prod

db-dev:
$(call COMPOSE_ENV,dev) up --build -d db
export NODE_ENV=dev && $(call COMPOSE_ENV) up --build -d db

db-alpha:
$(call COMPOSE_ENV,alpha) up --build -d db

db-prod:
$(call COMPOSE_ENV,prod) up --build -d db
export NODE_ENV=alpha && sudo $(call COMPOSE_ENV) up --build -d db

db: db-dev

Expand All @@ -29,25 +31,28 @@ redis-down:
${COMPOSE} down redis

redis-dev:
$(call COMPOSE_ENV,dev) up --build -d redis
export NODE_ENV=dev && $(call COMPOSE_ENV) up --build -d redis

redis-alpha:
$(call COMPOSE_ENV,alpha) up --build -d redis

redis-prod:
$(call COMPOSE_ENV,prod) up --build -d redis
export NODE_ENV=alpha && sudo $(call COMPOSE_ENV) up --build -d redis

api:
api-dev

api-dev:
$(call COMPOSE_ENV,dev) up --build --no-deps -d api
export NODE_ENV=dev && $(call COMPOSE_ENV) up --build --no-deps -d api

api-alpha:
$(call COMPOSE_ENV,alpha) up --build --no-deps -d api
export NODE_ENV=alpha && sudo $(call COMPOSE_ENV) up --build --no-deps -d api

api-prod:
$(call COMPOSE_ENV,prod) up --build --no-deps -d api
sudo docker build -t ft-world-api .
sudo docker run -d -p 80:80 --env-file config/.env ft-world-api

api-build:
sudo docker build -t ft-world-api .
sudo docker tag ft-world-api:latest public.ecr.aws/x9y9d0k9/ft-world-api:latest
sudo docker push public.ecr.aws/x9y9d0k9/ft-world-api:latest

db-init:
sudo yarn typeorm:run
Expand Down
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ https://www.42world.kr/

```
├── config
│ └── dev.env
│ └── .env.dev
├── src
│ ├── article
│ ├── auth
Expand All @@ -32,7 +32,11 @@ https://www.42world.kr/

## 기술스택
- Frontend: [React.js](https://reactjs.org/)
- Backend: [Nest.js](https://nestjs.com/)
- Backend
- [Nest.js](https://nestjs.com/)
- [TypeORM](https://typeorm.io/#/)
- [Redis](https://redis.io/)
- [Docker](https://www.docker.com/)

# 프로젝트
**! Docker 가 설치되어 있어야 합니다.**
Expand All @@ -54,12 +58,36 @@ https://www.42world.kr/
yarn install
```
## env 파일 형식
sample.env.dev 파일을 .env.dev 로 이름을 바꾸고 비어있는 부분을 채워주세요.
`GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET`, `GITHUB_CALLBACK_URL` 은 github oauth 로그인 관련 설정입니다.
이 링크를 참조하여 생성한 한 후 채워주세요 [github building-oauth-apps](https://docs.github.com/en/developers/apps/building-oauth-apps/creating-an-oauth-app)
`EMAIL_*`은 이메일 인증과 관련된 설정입니다.
완벽히 같지는 않지만 이 링크를 참조하여 원하는 설정을 채워주세요 [node-mailer](https://nodemailer.com/about/)
## 실행하기
- 아래 명령어를 입력하여 실행해주세요.
```
make dev
yarn start:dev
```
- 명령어는 디렉토리 최상단에서 실행해주세요.
## 테스트 실행하기
현재 e2e 테스트의 일부만 제대로 구성되어 있습니다.
다른 테스트 및 유닛테스트는 추후 보강 예정입니다.
```
./run_test_db.sh

yarn test:e2e ./test/app.e2e-spec.ts
```
# 기여하기
42world 커뮤니티 제작은 오픈소스로 진행되고 있습니다.
Expand Down Expand Up @@ -94,4 +122,4 @@ https://www.42world.kr/
질문이 생기면 이메일([email protected])로 언제든 연락주세요.
저장소에 별 달아주시는거 잊지마세요 ✨✨✨
저장소에 별 달아주시는거 잊지마세요 ✨✨✨
23 changes: 23 additions & 0 deletions config/sample.env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
MYSQL_DATABASE=ft_world
MYSQL_USER=ft_world
MYSQL_PASSWORD=ft_world
MYSQL_EXTERNAL_PORT=3306
API_EXTERNAL_PORT=8888
DB_HOST=db
DB_PORT=3306
DB_NAME=ft_world
DB_USER_NAME=
DB_USER_PASSWORD=
REDIS_HOST=redis6379
REDIS_PORT=6379
PORT=8888
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
GITHUB_CALLBACK_URL=http://localhost:3000/auth/github/callback
JWT_SECRET=
[email protected]
EMAIL_AUTH_PASSWORD=
EMAIL_HOST=smtp.gmail.com
EMAIL_FROM_USER_NAME=42world
EMAIL_ENDPOINT=http://localhost:8888/ft-auth
FRONT_URL=http://localhost:3000
26 changes: 25 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
version: '3.4'
services:
db:
image: mysql:5.7
platform: linux/x86_64
ports:
- '${DB_PORT:-2345}:3306'
environment:
- MYSQL_DATABASE=${DB_NAME}
- MYSQL_USER=${DB_USER_NAME}
- MYSQL_PASSWORD=${DB_USER_PASSWORD}
- MYSQL_ALLOW_EMPTY_PASSWORD=true
- MYSQL_INITDB_ARGS=--encoding=UTF-8
- TZ=Asia/Seoul
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
healthcheck:
test: 'mysqladmin ping -h localhost -u ${DB_USER_NAME} --password=${DB_USER_PASSWORD}'
interval: 5s
timeout: 1s
retries: 10
start_period: 10s
volumes:
- ./db:/var/lib/mysql
api:
build:
context: .
dockerfile: ./Dockerfile
ports:
- '${API_EXTERNAL_PORT:-8888}:8888'
- '${API_EXTERNAL_PORT:-8888}:${PORT:-8888}'
env_file:
- ./config/.env
environment:
- NODE_ENV=${NODE_ENV:-alpha}
depends_on:
- db
- redis

redis:
Expand Down
45 changes: 0 additions & 45 deletions docker-compose_backup.yml

This file was deleted.

2 changes: 1 addition & 1 deletion nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"collection": "@nestjs/schematics",
"sourceRoot": "",
"compilerOptions": {
"assets": [{ "include": "**/*.ejs" }],
"assets": [{ "include": "views/**/*.ejs" }],
"watchAssets": true
}
}
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start": "NODE_ENV=dev nest start",
"start:dev": "NODE_ENV=dev nest start --watch",
"start:debug": "NODE_ENV=dev nest start --debug --watch",
"start:prod": "node dist/main",
"start:prod": "NODE_ENV=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": "NODE_ENV=test jest --config ./test/jest-e2e.json",
"test:e2e": "NODE_ENV=test jest --runInBand --config ./test/e2e/jest-e2e.json",
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config src/database/ormconfig.ts",
"typeorm:migrate": "yarn typeorm migration:generate -n",
"typeorm:run": "yarn typeorm migration:run",
Expand All @@ -36,18 +36,20 @@
"@nestjs/platform-express": "^8.0.0",
"@nestjs/swagger": "^5.1.5",
"@nestjs/typeorm": "^8.0.2",
"aws-sdk": "^2.1074.0",
"axios": "^0.25.0",
"bcryptjs": "^2.4.3",
"cache-manager": "^3.6.0",
"cache-manager-ioredis": "^2.1.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"cookie-parser": "^1.4.6",
"csurf": "^1.11.0",
"ejs": "^3.1.6",
"morgan": "^1.10.0",
"mysql2": "^2.3.3",
"nest-aws-sdk": "^2.1.0",
"nest-winston": "^1.6.2",
"csurf": "^1.11.0",
"ejs": "^3.1.6",
"nodemailer": "^6.7.2",
"passport": "^0.5.2",
"passport-github2": "^0.1.12",
Expand Down
1 change: 1 addition & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Controller, Get } from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { Public } from '@auth/auth.decorator';

@ApiTags('Hello')
@Controller()
export class AppController {
Expand Down
24 changes: 22 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ import { AuthModule } from './auth/auth.module';
import { BestModule } from './best/best.module';
import { ReactionModule } from './reaction/reaction.module';
import { DatabaseModule } from './database/database.module';
import { getEnvPath } from './utils';
import { JwtAuthGuard } from './auth/jwt-auth.guard';
import { ormconfig } from './database/ormconfig';
import { FtCheckinModule } from './ft-checkin/ft-checkin.module';
import { AwsSdkModule } from 'nest-aws-sdk';
import {
AWS_ACCESS_KEY,
AWS_REGION,
AWS_SECRET_KEY,
} from '@root/config/constants';
import { ImageModule } from '@root/image/image.module';

@Module({
imports: [
ConfigModule.forRoot({
envFilePath: getEnvPath(),
envFilePath: 'config/.env',
isGlobal: true,
cache: true,
load: [ormconfig, configEmail],
Expand Down Expand Up @@ -72,6 +78,19 @@ import { FtCheckinModule } from './ft-checkin/ft-checkin.module';
}),
],
}),
AwsSdkModule.forRootAsync({
defaultServiceOptions: {
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => {
return {
region: configService.get(AWS_REGION),
accessKeyId: configService.get(AWS_ACCESS_KEY),
secretAccessKey: configService.get(AWS_SECRET_KEY),
};
},
},
}),
CommentModule,
UserModule,
ArticleModule,
Expand All @@ -82,6 +101,7 @@ import { FtCheckinModule } from './ft-checkin/ft-checkin.module';
BestModule,
ReactionModule,
FtCheckinModule,
ImageModule,
],
controllers: [AppController],
providers: [
Expand Down
4 changes: 2 additions & 2 deletions src/article/article.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export class ArticleController {
userId,
articleId,
);

this.articleService.increaseViewCount(article);
if (article.writerId !== userId)
this.articleService.increaseViewCount(article);
return { ...article, isLike };
}

Expand Down
2 changes: 1 addition & 1 deletion src/article/article.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class ArticleService {
}

decreaseLikeCount(article: Article): Promise<Article> {
if (article.likeCount < 1) {
if (article.likeCount <= 0) {
throw new NotAcceptableException('좋아요는 0이하가 될 수 없습니다.');
}
article.likeCount -= 1;
Expand Down
Loading

0 comments on commit 36d2910

Please sign in to comment.