- Created .gitignore to exclude build outputs, logs, and environment files. - Added nuxt.config.ts for project configuration, enabling Tailwind CSS and Pinia modules. - Initialized package.json with scripts for development and production, and added necessary dependencies. - Generated pnpm-lock.yaml for dependency management. - Created README.md with setup instructions and development guidelines. - Implemented server API examples in server/api/ directory, demonstrating various use cases. - Added middleware for logging requests and responses. - Included example Vue components and pages for server API interaction. - Established basic project structure for Nuxt 4 application development.
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
/**
|
|
* 케이스 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 };
|
|
});
|