/** * 케이스 8: server/routes/ vs server/api/ * * 차이점: * ┌─────────────────────────────────────────────────────────────┐ * │ server/api/hello.ts → URL: /api/hello (/api 자동 접두사) │ * │ server/routes/hello.ts → URL: /hello (접두사 없음) │ * └─────────────────────────────────────────────────────────────┘ * * server/routes/ 사용 사례: * - 외부 서비스 Webhook 수신 (/webhook/github, /webhook/stripe) * - RSS 피드 (/rss.xml) * - sitemap.xml (/sitemap.xml) * - 커스텀 URL 구조가 필요할 때 * * URL: POST /08-webhook * * 테스트: * fetch('/08-webhook', { * method: 'POST', * headers: { 'Content-Type': 'application/json', 'X-Webhook-Secret': 'my-secret' }, * body: JSON.stringify({ event: 'push', repo: 'my-project' }) * }) */ export default defineEventHandler(async (event) => { // 웹훅 시크릿 검증 (실제로는 HMAC 서명 검증) const secret = getHeader(event, "x-webhook-secret"); if (secret !== "my-secret") { throw createError({ statusCode: 401, statusMessage: "잘못된 웹훅 시크릿" }); } const payload = await readBody(event); console.log("웹훅 수신:", payload); // 웹훅 응답은 빠르게 200 반환 (처리는 백그라운드에서) return { received: true }; });