Fix Vercel deployment: add serverless compatibility and API routes

This commit is contained in:
2025-08-21 12:43:53 +09:00
parent 6f68196127
commit 9b9eb7f321
3 changed files with 29 additions and 20 deletions

4
api/index.js Normal file
View File

@@ -0,0 +1,4 @@
const app = require('../server');
// Vercel 서버리스 함수로 export
module.exports = app;

View File

@@ -766,23 +766,28 @@ app.use((req, res) => {
}); });
}); });
// 서버 시작 // Vercel 서버리스 환경을 위한 export
app.listen(PORT, () => { module.exports = app;
console.log(`🚀 자료실 서버가 포트 ${PORT}에서 실행중입니다.`);
console.log(`📱 Admin 페이지: http://localhost:${PORT}/admin/index.html`);
console.log(`🌐 Main 페이지: http://localhost:${PORT}/index.html`);
console.log(`📊 API: http://localhost:${PORT}/api/files`);
});
// 프로세스 종료 시 데이터베이스 연결 종료 // 로컬 개발 환경에서만 서버 시작
process.on('SIGINT', async () => { if (process.env.NODE_ENV !== 'production' || process.env.VERCEL !== '1') {
console.log('\n📝 서버를 종료합니다...'); app.listen(PORT, () => {
await db.close(); console.log(`🚀 자료실 서버가 포트 ${PORT}에서 실행중입니다.`);
process.exit(0); console.log(`📱 Admin 페이지: http://localhost:${PORT}/admin/index.html`);
}); console.log(`🌐 Main 페이지: http://localhost:${PORT}/index.html`);
console.log(`📊 API: http://localhost:${PORT}/api/files`);
});
process.on('SIGTERM', async () => { // 프로세스 종료 시 데이터베이스 연결 종료
console.log('\n📝 서버를 종료합니다...'); process.on('SIGINT', async () => {
await db.close(); console.log('\n📝 서버를 종료합니다...');
process.exit(0); await db.close();
}); process.exit(0);
});
process.on('SIGTERM', async () => {
console.log('\n📝 서버를 종료합니다...');
await db.close();
process.exit(0);
});
}

View File

@@ -2,14 +2,14 @@
"version": 2, "version": 2,
"builds": [ "builds": [
{ {
"src": "server.js", "src": "api/index.js",
"use": "@vercel/node" "use": "@vercel/node"
} }
], ],
"routes": [ "routes": [
{ {
"src": "/(.*)", "src": "/(.*)",
"dest": "/server.js" "dest": "/api/index.js"
} }
], ],
"env": { "env": {