Back with pages router, it was working fine. Now moved to App Router in a new app, not working.
I have been trying multiple variation, but no sitemap xml get generated. The thing is that, unlike the very basic example in next js doc, I have some pages on Prismic, other in my repo. Hence, I've tried this code, in vain:
import { MetadataRoute } from 'next'
import fetchAllTypesPages from '@/utils/fetchAllTypesPages'
import { createClient } from '@/prismicio'
// Ensure you have SITE_URL defined in your environment variables
const siteUrl = process.env.SITE_URL || 'https://guadeloupeloc.fr/' // Fallback in case it's not defined
type ChangeFrequency =
| 'always'
| 'hourly'
| 'daily'
| 'weekly'
| 'monthly'
| 'yearly'
| 'never'
interface Route {
url: string
lastModified: Date
changeFrequency: ChangeFrequency
priority: number
}
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const client = createClient()
// Fetch all static and dynamic routes
const pages = await fetchAllTypesPages(client)
return pages.map((page) => ({
url: `${siteUrl}${page.url}`,
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 0.7
}))
}
Not working neither. Not seeing any sitemap.xml being created, and when I hit it I get this error:
Application error: a server-side exception has occurred (see the server logs for more information).
Digest: 4204100638
And server errors:
[Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.] {
digest: '4204100638'
}