I am building Nextjs13 project and i am trying to implement sitemap.xml to my web application. I came across the problem with generating the sitemap.xml file in production. I am generating it dynamicly (will provide code below). The file is called sitemap.ts and it is in the root of my app folder, as the docs say it should be. So when i start my app in development mode, and i go to /sitemap.xml it fires the https request and gets newest data, as it should, but in production it does not call function that generates the newest data. Did any of you encountered that same problem, what should i do to fix that ?
>! The funcion i use to get all the serp pages to display routes in xml
export default async function getSitemapSerps() {
const res = await fetch(
url,
{ cache: 'no-store' }
);
if (!res.ok) return null;
return res.json();
}
>! The sitemap.ts file
import { MetadataRoute } from 'next';
import getSitemapSerps from './lib/getSitemapSerps';
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const baseUrl = 'https://url';
const sitemapSerpsData: Promise<number[] | []> = getSitemapSerps();
const sitemapSerps = await sitemapSerpsData;
const serpUrls = sitemapSerps.map((sitemap) => ({
url: `${baseUrl}/dashboard/serp/${sitemap.toString()}`,
lastModified: new Date(),
}));
return [
...serpUrls,
];
}
I tried everything i came across!