From 43d080244225d71f1a58cd2023dec9eaa59b6c23 Mon Sep 17 00:00:00 2001 From: vibsin9322 Date: Thu, 21 Aug 2025 13:06:35 +0900 Subject: [PATCH] Fix Vercel deployment issues: add CORS fix, session config, and simple API version --- api/simple.js | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++ server.js | 14 ++++- vercel.json | 4 +- 3 files changed, 169 insertions(+), 4 deletions(-) create mode 100644 api/simple.js diff --git a/api/simple.js b/api/simple.js new file mode 100644 index 0000000..ae0d974 --- /dev/null +++ b/api/simple.js @@ -0,0 +1,155 @@ +const express = require('express'); +const cors = require('cors'); +const path = require('path'); + +const app = express(); + +// CORS 설정 - 모든 도메인 허용 +app.use(cors({ + origin: true, + credentials: true +})); + +// JSON 파싱 +app.use(express.json({ limit: '10mb' })); +app.use(express.urlencoded({ extended: true, limit: '10mb' })); + +// 정적 파일 서빙 +app.use(express.static(path.join(__dirname, '..'))); + +// 헬스 체크 +app.get('/health', (req, res) => { + res.json({ + success: true, + message: 'Jaryo File Manager is running', + timestamp: new Date().toISOString(), + environment: process.env.NODE_ENV || 'development' + }); +}); + +// 루트 경로 +app.get('/', (req, res) => { + res.send(` + + + + + + Jaryo File Manager + + + +
+

🚀 Jaryo File Manager

+ +
+

✅ 배포 성공!

+

Vercel에서 성공적으로 배포되었습니다.

+

배포 시간: ${new Date().toLocaleString('ko-KR')}

+
+ +
+

📁 주요 기능

+
    +
  • 파일 업로드 및 관리
  • +
  • 카테고리별 분류
  • +
  • 파일 검색 및 다운로드
  • +
  • 관리자 기능
  • +
+
+ +
+

🔧 API 엔드포인트

+

헬스 체크

+

파일 목록 API

+

카테고리 API

+
+ +
+

📱 페이지

+

메인 페이지

+

관리자 페이지

+
+
+ + + `); +}); + +// API 라우트들 +app.get('/api/files', (req, res) => { + res.json({ + success: true, + data: [], + message: '파일 목록 API (데모 모드)' + }); +}); + +app.get('/api/categories', (req, res) => { + res.json({ + success: true, + data: [ + { id: 1, name: '문서', description: '문서 파일' }, + { id: 2, name: '이미지', description: '이미지 파일' }, + { id: 3, name: '기타', description: '기타 파일' } + ], + message: '카테고리 목록' + }); +}); + +// 404 핸들러 +app.use((req, res) => { + res.status(404).json({ + success: false, + error: '요청한 리소스를 찾을 수 없습니다.', + path: req.path + }); +}); + +module.exports = app; diff --git a/server.js b/server.js index cd8fb40..0441cbd 100644 --- a/server.js +++ b/server.js @@ -16,7 +16,7 @@ const db = new DatabaseHelper(); // 미들웨어 설정 app.use(cors({ - origin: ['http://localhost:3001', 'http://127.0.0.1:3001'], + origin: true, // 모든 도메인 허용 (Vercel 배포용) credentials: true })); app.use(express.json({ limit: '50mb' })); @@ -28,7 +28,7 @@ app.use(session({ resave: false, saveUninitialized: false, cookie: { - secure: false, // HTTPS에서는 true로 설정 + secure: process.env.NODE_ENV === 'production', // Vercel에서는 HTTPS httpOnly: true, maxAge: 24 * 60 * 60 * 1000 // 24시간 } @@ -53,6 +53,16 @@ app.get('/', (req, res) => { res.redirect('/index.html'); }); +// 헬스 체크 엔드포인트 +app.get('/health', (req, res) => { + res.json({ + success: true, + message: 'Jaryo File Manager is running', + timestamp: new Date().toISOString(), + environment: process.env.NODE_ENV || 'development' + }); +}); + // Multer 설정 (파일 업로드) const storage = multer.diskStorage({ destination: (req, file, cb) => { diff --git a/vercel.json b/vercel.json index 18babe3..33c1c99 100644 --- a/vercel.json +++ b/vercel.json @@ -2,14 +2,14 @@ "version": 2, "builds": [ { - "src": "api/index.js", + "src": "api/simple.js", "use": "@vercel/node" } ], "routes": [ { "src": "/(.*)", - "dest": "/api/index.js" + "dest": "/api/simple.js" } ], "env": {