Skip to content

Commit

Permalink
Fix: generateSitemaps in production giving 404 (#62212)
Browse files Browse the repository at this point in the history
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: Jiachi Liu <[email protected]>
  • Loading branch information
abhinaypandey02 and huozhi committed Mar 4, 2024
1 parent 400b57c commit 0a2d775
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down

0 comments on commit 0a2d775

Please sign in to comment.