diff --git a/api/files.js b/api/files.js new file mode 100644 index 0000000..ae4fc90 --- /dev/null +++ b/api/files.js @@ -0,0 +1,40 @@ +// 파일 API +module.exports = (req, res) => { + // CORS 헤더 설정 + res.setHeader('Access-Control-Allow-Origin', '*'); + res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); + res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); + + if (req.method === 'OPTIONS') { + res.status(200).end(); + return; + } + + // 샘플 파일 데이터 + const files = [ + { + id: 1, + title: '샘플 문서', + description: '데모용 파일입니다', + category: '문서', + tags: ['샘플', '테스트'], + created_at: new Date().toISOString(), + file_url: '#' + }, + { + id: 2, + title: '이미지 파일', + description: '예시 이미지', + category: '이미지', + tags: ['샘플'], + created_at: new Date().toISOString(), + file_url: '#' + } + ]; + + res.status(200).json({ + success: true, + data: files, + message: '파일 목록을 성공적으로 불러왔습니다.' + }); +}; \ No newline at end of file diff --git a/api/simple.js b/api/simple.js index f05070d..a857985 100644 --- a/api/simple.js +++ b/api/simple.js @@ -1,5 +1,5 @@ // Vercel Serverless 함수 핸들러 -export default function handler(req, res) { +module.exports = function handler(req, res) { // CORS 헤더 설정 res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); @@ -27,7 +27,7 @@ export default function handler(req, res) { // 루트 경로 if (url === '/' || url === '/api') { res.setHeader('Content-Type', 'text/html'); - res.send(` + res.end(` diff --git a/api/test.js b/api/test.js new file mode 100644 index 0000000..bcca53f --- /dev/null +++ b/api/test.js @@ -0,0 +1,21 @@ +// 테스트용 간단한 API +module.exports = (req, res) => { + // CORS 헤더 설정 + res.setHeader('Access-Control-Allow-Origin', '*'); + res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); + res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); + + if (req.method === 'OPTIONS') { + res.status(200).end(); + return; + } + + // 간단한 응답 + res.status(200).json({ + success: true, + message: 'API가 정상 작동합니다!', + timestamp: new Date().toISOString(), + url: req.url, + method: req.method + }); +}; \ No newline at end of file diff --git a/package.json b/package.json index 4fb5f3b..e7e4075 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "name": "jaryo-file-manager", "version": "2.0.0", "description": "자료실 파일 관리 시스템 - Vercel Serverless", - "type": "module", "scripts": { "dev": "vercel dev", "build": "echo 'Build complete'", diff --git a/vercel.json b/vercel.json index 1ec4e56..5d754c9 100644 --- a/vercel.json +++ b/vercel.json @@ -1,59 +1,29 @@ { "version": 2, - "builds": [ - { - "src": "api/simple.js", - "use": "@vercel/node" - } - ], "routes": [ { - "src": "/api/(.*)", - "dest": "/api/simple.js" + "src": "/api/test", + "dest": "/api/test.js" }, { - "src": "/health", - "dest": "/api/simple.js" + "src": "/api/files/public", + "dest": "/api/files.js" }, { - "src": "/(.*\\.(css|js|json|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot|html))", - "headers": { - "Cache-Control": "public, max-age=31536000, immutable" - }, + "src": "/api/files", + "dest": "/api/files.js" + }, + { + "src": "/(.*\\.(css|js|json|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot))", "dest": "/$1" }, - { - "src": "/index\\.html", - "headers": { - "Cache-Control": "public, max-age=0, must-revalidate" - }, - "dest": "/index.html" - }, { "src": "/admin/(.*)", "dest": "/admin/$1" }, - { - "src": "^/$", - "dest": "/api/simple.js" - }, { "src": "/(.*)", "dest": "/index.html" } - ], - "headers": [ - { - "source": "/api/(.*)", - "headers": [ - { - "key": "Cache-Control", - "value": "public, max-age=0, s-maxage=86400" - } - ] - } - ], - "env": { - "NODE_ENV": "production" - } + ] }