Skip to content

Commit 9a6acbc

Browse files
authored
Wesocket서버 및 API 서버 분리 (#3)
* fix: api 서버와 websocket 분리를 위해 backend 서버 네임 변경 * feature/split api websocket * fix: 분리 후 중복되는 코드 삭제
1 parent 86fa8f4 commit 9a6acbc

File tree

99 files changed

+2261
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2261
-118
lines changed

docker-compose.override.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ services:
2222
timeout: 5s
2323
retries: 3
2424
command: --bind-address=0.0.0.0
25-
backend:
25+
26+
collaborative:
2627
build:
2728
context: .
28-
dockerfile: ./packages/backend/Dockerfile
29-
container_name: backend
29+
dockerfile: ./packages/collaborative/Dockerfile
30+
container_name: collaborative
3031
ports:
31-
- "3000:3000"
32+
- "3001:3001"
3233
- "9001:9001"
3334
depends_on:
3435
mysql:
@@ -49,6 +50,32 @@ services:
4950
- LOG_LEVEL=info
5051
networks:
5152
- app-network
53+
api:
54+
build:
55+
context: .
56+
dockerfile: ./packages/api/Dockerfile
57+
container_name: api
58+
ports:
59+
- "3000:3000"
60+
depends_on:
61+
mysql:
62+
condition: service_healthy
63+
mongodb:
64+
condition: service_healthy
65+
environment:
66+
- MYSQL_HOST=mysql-container
67+
- MYSQL_PORT=3306
68+
- MYSQL_DATABASE=dev_db
69+
- MYSQL_PASSWORD=1234
70+
- MYSQL_USER=honey
71+
- NODE_ENV=dev
72+
- MONGO_HOST=mongodb-container
73+
- MONGO_USER=honey
74+
- MONGO_PASSWORD=1234
75+
- MONGO_DB=dev_db
76+
- LOG_LEVEL=info
77+
networks:
78+
- app-network
5279

5380
frontend:
5481
build:
@@ -58,7 +85,9 @@ services:
5885
ports:
5986
- "80:80"
6087
depends_on:
61-
backend:
88+
collaborative:
89+
condition: service_started
90+
api:
6291
condition: service_started
6392
networks:
6493
- app-network

docker-compose.prod.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ services:
1616
timeout: 5s
1717
retries: 3
1818

19-
backend:
20-
container_name: backend
19+
api:
20+
container_name: api
2121
ports:
2222
- "3000:3000"
2323
build:
@@ -45,7 +45,7 @@ services:
4545
frontend:
4646
container_name: frontend
4747
depends_on:
48-
backend:
48+
api:
4949
condition: service_started
5050
ports:
5151
- "80:80"

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
services:
2-
backend:
2+
api:
33
build:
44
context: .
5-
dockerfile: ./packages/backend/Dockerfile
5+
dockerfile: ./packages/api/Dockerfile
66
restart: unless-stopped
77
environment:
88
- NODE_ENV=development

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"private": "true",
66
"scripts": {
7-
"lint": "eslint --filter \"frontend,backend\" lint",
7+
"lint": "eslint --filter \"frontend,api\" lint",
88
"test": "echo \"Error: no test specified\" && exit 1",
99
"prepare": "husky"
1010
},
File renamed without changes.
File renamed without changes.

packages/backend/Dockerfile renamed to packages/api/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ WORKDIR /app
44

55
RUN apk add --no-cache python3 make g++ && npm install -g pnpm
66
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
7-
COPY ./packages/backend ./packages/backend/
7+
COPY ./packages/api ./packages/api/
88
COPY ./packages/shared ./packages/shared/
99

1010
RUN HUSKY=0 pnpm install --frozen-lockfile
1111

12-
RUN cd ./packages/backend && pnpm build
12+
RUN cd ./packages/api && pnpm build
1313

1414
FROM node:20-alpine AS production
1515

1616
WORKDIR /app
1717

1818
COPY --from=builder /app .
1919

20-
WORKDIR /app/packages/backend
20+
WORKDIR /app/packages/api
2121

2222
EXPOSE 3000
2323

File renamed without changes.

packages/backend/package.json renamed to packages/api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "backend",
2+
"name": "api",
33
"version": "0.0.1",
44
"description": "",
55
"author": "",
@@ -11,7 +11,7 @@
1111
"start": "nest start",
1212
"start:dev": "nest start --watch",
1313
"start:debug": "nest start --debug --watch",
14-
"start:prod": "node dist/backend/src/main.js",
14+
"start:prod": "node dist/api/src/main.js",
1515
"test": "jest",
1616
"test:watch": "jest --watch",
1717
"test:cov": "jest --coverage",

packages/api/src/app.module.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Logger, Module, OnModuleInit } from '@nestjs/common';
2+
import { ConfigModule, ConfigService } from '@nestjs/config';
3+
import { MongooseModule } from '@nestjs/mongoose';
4+
import { TypeOrmModule } from '@nestjs/typeorm';
5+
6+
import { getMongooseConfig } from './common/config/mongo.config';
7+
import { getTypeOrmConfig } from './common/config/typeorm.config';
8+
import { NoteModule } from './note/note.module';
9+
import { SpaceModule } from './space/space.module';
10+
import { TestModule } from './test/test.module';
11+
12+
@Module({
13+
imports: [
14+
ConfigModule.forRoot({
15+
isGlobal: true,
16+
}),
17+
MongooseModule.forRootAsync({
18+
inject: [ConfigService],
19+
useFactory: getMongooseConfig,
20+
}),
21+
TypeOrmModule.forRootAsync({
22+
inject: [ConfigService],
23+
useFactory: getTypeOrmConfig,
24+
}),
25+
SpaceModule,
26+
NoteModule,
27+
TestModule,
28+
],
29+
})
30+
export class AppModule implements OnModuleInit {
31+
private readonly logger = new Logger(AppModule.name);
32+
33+
async onModuleInit(): Promise<void> {
34+
this.logger.debug('Application initialized for debug');
35+
this.logger.log('Application initialized', {
36+
module: 'AppModule',
37+
environment: process.env.NODE_ENV ?? 'development',
38+
timestamp: new Date().toISOString(),
39+
});
40+
}
41+
}

0 commit comments

Comments
 (0)