export async function GET({ fetch, setHeaders }) {
	setHeaders({
		'Content-Type': 'application/xml'
	});

	const site = 'https://koreanskincareandclinic.com';
	const response = await fetch('https://api.koreanskincareandclinic.com/api/product');
	if (!response.ok) {
		throw new Error('Failed to fetch posts.');
	}
	const products = await response.json();

	const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>${site}</loc>
<changefreq>daily</changefreq>
<priority>0.7</priority>
</url>
${products.products
	.map(
		(/** @type {{ id: any;slug:string; published_at: string; }} */ product) => `
<url>
<loc>${site}/product/${product.id}/${product.slug}</loc>
<changefreq>weekly</changefreq>
</url>
`
	)
	.join('')}
</urlset>`;
	return new Response(sitemap);
}
