Unverified Commit f38dc188 authored by Abhinay Pandey's avatar Abhinay Pandey Committed by GitHub

Fix: generateSitemaps in production giving 404 (#62212)

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

### Why?
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)

### How?
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 eaa7606d
...@@ -211,8 +211,11 @@ export async function GET(_, ctx) { ...@@ -211,8 +211,11 @@ export async function GET(_, ctx) {
throw new Error('id property is required for every item returned from generateSitemaps') throw new Error('id property is required for every item returned from generateSitemaps')
} }
} }
let itemID = item.id.toString()
return item.id.toString() === targetId if(process.env.NODE_ENV === 'production') {
itemID += '.xml'
}
return itemID === targetId
})?.id })?.id
if (id == null) { if (id == null) {
return new NextResponse('Not Found', { return new NextResponse('Not Found', {
......
...@@ -200,7 +200,9 @@ createNextDescribe( ...@@ -200,7 +200,9 @@ createNextDescribe(
const ids = ['child0', 'child1', 'child2', 'child3'] const ids = ['child0', 'child1', 'child2', 'child3']
function fetchSitemap(id) { function fetchSitemap(id) {
return next return next
.fetch(isNextDev ? `/gsp/sitemap.xml/${id}` : `/gsp/sitemap/${id}`) .fetch(
isNextDev ? `/gsp/sitemap.xml/${id}` : `/gsp/sitemap/${id}.xml`
)
.then((res) => res.text()) .then((res) => res.text())
} }
......
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