Skip to content

Commit

Permalink
Merge pull request #268 from boostcampwm-2024/chore/be/#242-devNginxF…
Browse files Browse the repository at this point in the history
…or4th

[BE][Chore] #242 : 4주차 배포를 위한 세팅
  • Loading branch information
happyhyep authored Nov 26, 2024
2 parents f0a2f0d + ee33e39 commit 117e1b4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"license": "ISC",
"dependencies": {
"bcrypt": "^5.1.1",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.21.1",
"express-validator": "^7.2.0",
Expand Down
4 changes: 2 additions & 2 deletions backend/src/websocketServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const initializeWebSocketServer = server => {
verifyClient: (info, done) => {
const { origin } = info;

if (origin === 'http://localhost:5173') {
if (origin === 'http://localhost:5173' || origin === 'https://ddara.kro.kr') {
done(true);
} else {
done(false, 403, 'Forbidden: Origin not allowed');
Expand All @@ -24,7 +24,7 @@ export const initializeWebSocketServer = server => {
wss.on('connection', (ws, req) => {
// URL에서 token 추출
// TODO: 프론트 라우터 및 token 설정 완료 후 테스트
const url = new URL(req.url, `http://${req.headers.host}`);
const url = new URL(req.url, `https://${req.headers.host}`);
const token = url.searchParams.get('token');

if (!token) {
Expand Down
18 changes: 14 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,33 @@ services:
build:
context: .
dockerfile: backend/Dockerfile
ports:
- "3001:3001"
environment:
- NODE_ENV=production
networks:
- app-network

frontend:
build:
context: .
dockerfile: frontend/Dockerfile
networks:
- app-network
depends_on:
- backend

nginx:
image: nginx:alpine
volumes:
- /etc/letsencrypt:/etc/letsencrypt
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
- "80:80"
networks:
- app-network
- "443:443"
depends_on:
- backend
- frontend
networks:
- app-network

networks:
app-network:
Expand Down
31 changes: 31 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 1. 베이스 이미지 설정 (Node.js 18 사용)
FROM node:18 AS builder

# 2. 작업 디렉토리 설정
WORKDIR /app

# 3. root의 패키지 파일 복사
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./

# 4. pnpm 설치
RUN npm install -g pnpm

# 5. 전체 의존성 설치 (root)
RUN pnpm install

# 6. 프론트엔드 폴더 복사
COPY frontend /app/frontend

# 7. 작업 디렉토리 변경
WORKDIR /app/frontend

# 8. frontend 의존성 설치
RUN pnpm install

# 8. 빌드 실행
RUN pnpm build

# 9. Nginx 이미지를 사용해 정적 파일 제공
FROM nginx:alpine
COPY --from=builder /app/frontend/dist /usr/share/nginx/html
EXPOSE 80

0 comments on commit 117e1b4

Please sign in to comment.