Commit 0a2d7754 authored by Abhinay Pandey's avatar Abhinay Pandey Committed by Jiachi Liu

Fix: generateSitemaps in production giving 404 (#62212)

generateSitemaps function returns a 404 for /sitemap/[id].xml in
production

While finding the correct sitemap partition from the array, we check the
param against the id. Which works in dev because id and param are both
without trailing .xml. But it fails in production as param has a
trailing .xml (/sitemap/[id] works in production because it falls back
to dynamic loading and param and id are both without .xml)

If we are in production environment, check the id with a trailing .xml
because that's whats returned from generateStaticParams, an array of
__metadata_id__ with trailing .xml

Fixes #61969

---------
Co-authored-by: 's avatarJiachi Liu <inbox@huozhi.im>
parent 400b57cf
......@@ -204,7 +204,11 @@ export async function GET(_, ctx) {
throw new Error('id property is required for every item returned from generateSitemaps')
}
}
return item.id.toString() === targetId
let itemID = item.id.toString()
if(process.env.NODE_ENV === 'production') {
itemID += '.xml'
}
return itemID === targetId
})?.id
if (id == null) {
return new NextResponse('Not Found', {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment