Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions front-end/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@ dist-ssr

.env*

*.pem

vercel*
*.pem
2 changes: 1 addition & 1 deletion front-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"prebuild": "node copyCmaps.js",
"prebuild": "node copyCmaps.js && node vercelRewrite.js",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
Expand Down
12 changes: 12 additions & 0 deletions front-end/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rewrites": [
{
"source": "/api/:path*",
"destination": "VITE_API_URL/:path*"
},
{
"source": "/:path((?!api).*)",
"destination": "/index.html"
}
]
}
29 changes: 29 additions & 0 deletions front-end/vercelRewrite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// vercel-prebuild.js
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const apiUrl = process.env.VITE_API_URL;
if (!apiUrl) {
console.error('Error: VITE_API_URL 환경변수가 설정되어 있지 않습니다.');
process.exit(1);
}

const vercelJsonPath = path.join(__dirname, 'vercel.json');

try {
// vercel.json 파일 읽기
const fileContent = fs.readFileSync(vercelJsonPath, 'utf8');

// 파일 내의 모든 "VITE_API_URL" 문자열을 실제 환경변수 값으로 치환
const updatedContent = fileContent.replace(/VITE_API_URL/g, apiUrl);

// 치환된 내용을 다시 vercel.json 파일에 기록
fs.writeFileSync(vercelJsonPath, updatedContent, 'utf8');
console.log('vercel.json 파일이 성공적으로 업데이트되었습니다.');
} catch (error) {
console.error('vercel.json 파일 처리 중 에러 발생:', error);
process.exit(1);
}