- 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.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
/**
|
|
* 케이스 8-b: sitemap.xml
|
|
*
|
|
* server/routes/ 사용 사례 — /api 접두사 없이 /sitemap.xml URL로 직접 제공
|
|
*
|
|
* URL: GET /sitemap.xml
|
|
*/
|
|
|
|
export default defineEventHandler((event) => {
|
|
// XML Content-Type 지정
|
|
setHeader(event, "Content-Type", "application/xml");
|
|
|
|
const baseUrl = "https://example.com";
|
|
|
|
// 실제 프로젝트에서는 DB나 파일 시스템에서 동적으로 URL 목록을 가져옴
|
|
const pages = [
|
|
{ url: "/", lastmod: "2026-04-01", changefreq: "daily", priority: "1.0" },
|
|
{ url: "/about", lastmod: "2026-03-15", changefreq: "monthly", priority: "0.8" },
|
|
{ url: "/blog", lastmod: "2026-04-07", changefreq: "weekly", priority: "0.9" },
|
|
{ url: "/blog/nuxt4-release", lastmod: "2026-04-01", changefreq: "yearly", priority: "0.7" },
|
|
{ url: "/contact", lastmod: "2026-01-01", changefreq: "yearly", priority: "0.5" },
|
|
];
|
|
|
|
const urls = pages
|
|
.map(
|
|
(page) => `
|
|
<url>
|
|
<loc>${baseUrl}${page.url}</loc>
|
|
<lastmod>${page.lastmod}</lastmod>
|
|
<changefreq>${page.changefreq}</changefreq>
|
|
<priority>${page.priority}</priority>
|
|
</url>`
|
|
)
|
|
.join("");
|
|
|
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
${urls}
|
|
</urlset>`;
|
|
});
|