I'm new to NextJs and trying to create an xml file. I followed below article but 'getServerSideProps' method was not triggered and I see below message in console
API resolved without sending a response for /api/sitemap.xml, this may result in stalled requests.
https://www.learnbestcoding.com/post/16/nextjs-generate-sitemap-dynamically#sitemapXml
const Sitemap = () => {};
const toUrl = (route) =>
`<url><loc>${route.url}</loc><lastmod>${route.lastmod}</lastmod></url>`;
const createSitemap = (urlList) =>
`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
${urlList.map((url) => toUrl(url)).join("")}
</urlset>`;
export async function getServerSideProps({ res, req }) {
const siteMapJson = await fetch(`https://www.exampleapi.com/getsitemap`);
console.log("::::::::::::::::::",siteMapJson)
const urlList = await siteMapJson.json();
const sitemap = createSitemap(urlList);
res.setHeader("Content-Type", "text/xml");
res.write(sitemap);
res.end();
return { props: { results : {urlList}}}
};
export default Sitemap;
Can anyone help me.