Skip to content

Commit 9f83e88

Browse files
committed
Merge branch 'frontend-devops'
2 parents 4833a00 + 4d8bd56 commit 9f83e88

File tree

10 files changed

+98
-16
lines changed

10 files changed

+98
-16
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ DevOps/nginx/ssl/
2121
DevOps/.env
2222

2323
DevOps/docker-compose.prod.yml
24-
DevOps/.env.prod
24+
DevOps/.env.prod
25+
DevOps/.env.dev
26+
27+
frontend/.env.production

DevOps/.env.dev

Lines changed: 0 additions & 2 deletions
This file was deleted.

DevOps/docker-compose.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ services:
3838
ports:
3939
- "443:443"
4040
- "80:80"
41-
env_file:
42-
- .env.dev
43-
- .env
4441
depends_on:
4542
- frontend
4643
- backend

DevOps/nginx/Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
FROM nginx:stable-alpine
2-
WORKDIR /etc/nginx
32

4-
COPY default.conf.template /etc/nginx/conf.d/default.conf.template
3+
# nginx 설정 복사
4+
COPY default.conf.template /etc/nginx/conf.d/default.conf
55

6-
CMD ["/bin/sh", "-c", "envsubst '$$SSL_CERT_PATH $$SSL_KEY_PATH' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"]
6+
# 정적 파일은 frontend 컨테이너에서 서빙하므로 제거
7+
# COPY dist/ /usr/share/nginx/html
8+
9+
EXPOSE 80 443

DevOps/nginx/default.conf.template

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,31 @@ server {
1111
ssl_certificate /etc/letsencrypt/live/tukcbu.com/fullchain.pem;
1212
ssl_certificate_key /etc/letsencrypt/live/tukcbu.com/privkey.pem;
1313

14+
# API 요청을 backend로 프록시
1415
location /api/v1/ {
1516
proxy_pass http://backend:8080/api/v1/;
1617
proxy_set_header Host $host;
1718
proxy_set_header X-Real-IP $remote_addr;
19+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
20+
proxy_set_header X-Forwarded-Proto $scheme;
1821
}
1922

23+
# 정적 파일은 frontend 컨테이너에서 직접 서빙
2024
location / {
2125
proxy_pass http://frontend:80;
2226
proxy_set_header Host $host;
2327
proxy_set_header X-Real-IP $remote_addr;
28+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
29+
proxy_set_header X-Forwarded-Proto $scheme;
2430
proxy_http_version 1.1;
2531
proxy_set_header Upgrade $http_upgrade;
2632
proxy_set_header Connection 'upgrade';
33+
34+
# 정적 파일 캐싱 설정
35+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
36+
proxy_pass http://frontend:80;
37+
expires 1y;
38+
add_header Cache-Control "public, immutable";
39+
}
2740
}
2841
}

backend/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ FROM eclipse-temurin:17-jdk AS build
22

33
WORKDIR /app
44

5-
# Gradle wrapper 복사
5+
# Gradle wrapper 복사 및 실행 권한 부여
66
COPY gradlew .
77
COPY gradle gradle
8+
RUN chmod +x gradlew
89

910
# 소스 복사
1011
COPY build.gradle .
@@ -21,4 +22,5 @@ WORKDIR /app
2122

2223
COPY --from=build /app/build/libs/*.jar app.jar
2324

24-
ENTRYPOINT ["nohup", "java", "-jar", "app.jar"]
25+
EXPOSE 8080
26+
ENTRYPOINT ["java", "-jar", "app.jar"]

frontend/Dockerfile

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1-
FROM node:18-alpine as build
1+
FROM nginx:stable-alpine
2+
3+
# Node.js 설치
4+
RUN apk add --no-cache nodejs npm
5+
26
WORKDIR /app
37

4-
COPY .env .env
8+
# .env 파일이 있는 경우에만 복사 (선택적)
9+
COPY .env* ./
510

11+
# Copy package files
612
COPY package*.json ./
713
RUN npm install
814

15+
# Copy source code
916
COPY . .
17+
18+
# 빌드 시 환경변수 설정
19+
ENV VITE_API_URL=/api/v1
1020
RUN npm run build
21+
22+
# Copy built files to nginx directory
23+
RUN cp -r dist/* /usr/share/nginx/html/
24+
25+
# Copy nginx configuration
26+
COPY nginx.conf /etc/nginx/conf.d/default.conf
27+
28+
EXPOSE 80
29+
CMD ["nginx", "-g", "daemon off;"]

frontend/nginx.conf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
server {
2+
listen 80;
3+
server_name localhost;
4+
5+
root /usr/share/nginx/html;
6+
index index.html;
7+
8+
# SPA 라우팅을 위한 설정
9+
location / {
10+
try_files $uri $uri/ /index.html;
11+
}
12+
13+
# 정적 파일 캐싱
14+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
15+
expires 1y;
16+
add_header Cache-Control "public, immutable";
17+
}
18+
19+
# gzip 압축
20+
gzip on;
21+
gzip_vary on;
22+
gzip_min_length 1024;
23+
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
24+
}

frontend/src/hooks/useLogin.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ref } from "vue";
22
import { useRouter } from "vue-router";
33
import { useUserStore } from "../stores/userStore";
4+
import { API_ENDPOINTS } from "../utils/api";
45

56
interface LoginParams {
67
studentId: string;
@@ -14,8 +15,6 @@ export function useLogin() {
1415
const router = useRouter();
1516

1617
const handleLogin = async ({ studentId = "", password = "" }: LoginParams): Promise<void> => {
17-
const SERVER_URL = import.meta.env.VITE_API_URL;
18-
1918
if (!studentId || !password) {
2019
errorMessage.value = "아이디와 비밀번호를 입력하세요.";
2120
alert(errorMessage.value);
@@ -25,7 +24,7 @@ export function useLogin() {
2524
const studentNumber = Number(studentId.replace(/^cbu/, ""));
2625

2726
try {
28-
const response = await fetch(`${SERVER_URL}/login`, {
27+
const response = await fetch(API_ENDPOINTS.LOGIN, {
2928
method: "POST",
3029
headers: {
3130
"Content-Type": "application/json",

frontend/src/utils/api.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// API URL 설정
2+
const getApiUrl = (): string => {
3+
// 환경변수가 설정되어 있으면 사용, 없으면 기본값 사용
4+
const envUrl = import.meta.env.VITE_API_URL;
5+
6+
if (envUrl && envUrl !== 'undefined') {
7+
return envUrl;
8+
}
9+
10+
// 기본값: 현재 도메인의 /api/v1
11+
return '/api/v1';
12+
};
13+
14+
export const API_BASE_URL = getApiUrl();
15+
16+
// API 엔드포인트들
17+
export const API_ENDPOINTS = {
18+
LOGIN: `${API_BASE_URL}/login`,
19+
SIGNUP: `${API_BASE_URL}/login/signup`,
20+
MAIL_SEND: `${API_BASE_URL}/mail/send`,
21+
MAIL_VERIFY: `${API_BASE_URL}/mail/verify`,
22+
VERIFY_USER: `${API_BASE_URL}/verify`,
23+
CHANGE_PASSWORD: `${API_BASE_URL}/change-password`,
24+
} as const;

0 commit comments

Comments
 (0)