-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove auto appending xml extension to dynamic sitemap routes (#65507)
### What Remove the auto appending `.xml` extension to the sitemap routes when it's a dynamic route. ### Why Previously we were adding `.xml` to `/[...paths/]sitemap` routes, but the bad part is when you use it to generate multiple sitemaps with `generateSitemaps` in format like `/[...paths/]sitemap.xml/[id]`, which doesn't look good in url format and it can be inferred as xml with content-type. Hence we don't need to add `.xml` in the url. Before this change it could also result into the different url between dev and prod: dev: `/sitemap.xml/[id]` prod: `/sitemap/[id].xml` Now it's going to be aligned as `/sitemap/[id]`. Users can add extension flexiblely. Closes NEXT-3357
- Loading branch information
Showing
10 changed files
with
115 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 18 additions & 17 deletions
35
test/e2e/app-dir/dynamic-in-generate-params/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
import { type NextInstance, nextTestSetup } from 'e2e-utils' | ||
import type { Response } from 'node-fetch' | ||
|
||
async function getLastModifiedTime(next: NextInstance, pathname: string) { | ||
const content = await (await next.fetch(pathname)).text() | ||
return content.match(/<lastmod>([^<]+)<\/lastmod>/)[1] | ||
} | ||
|
||
function assertSitemapResponse(res: Response) { | ||
expect(res.status).toBe(200) | ||
expect(res.headers.get('content-type')).toContain('application/xml') | ||
} | ||
|
||
describe('app-dir - dynamic in generate params', () => { | ||
const { next, isNextDev } = nextTestSetup({ | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
skipDeployment: true, | ||
}) | ||
|
||
it('should render sitemap with generateSitemaps in force-dynamic config dynamically', async () => { | ||
const firstTime = await getLastModifiedTime( | ||
next, | ||
isNextDev ? 'sitemap.xml/0' : '/sitemap/0.xml' | ||
) | ||
const secondTime = await getLastModifiedTime( | ||
next, | ||
isNextDev ? 'sitemap.xml/0' : '/sitemap/0.xml' | ||
) | ||
const firstTime = await getLastModifiedTime(next, 'sitemap/0') | ||
const secondTime = await getLastModifiedTime(next, 'sitemap/0') | ||
|
||
expect(firstTime).not.toEqual(secondTime) | ||
}) | ||
|
||
it('should be able to call while generating multiple dynamic sitemaps', async () => { | ||
expect( | ||
(await next.fetch(isNextDev ? 'sitemap.xml/0' : '/sitemap/0.xml')).status | ||
).toBe(200) | ||
expect( | ||
(await next.fetch(isNextDev ? 'sitemap.xml/1' : '/sitemap/1.xml')).status | ||
).toBe(200) | ||
const res0 = await next.fetch('sitemap/0') | ||
const res1 = await next.fetch('sitemap/1') | ||
assertSitemapResponse(res0) | ||
assertSitemapResponse(res1) | ||
}) | ||
|
||
it('should be able to call fetch while generating multiple dynamic pages', async () => { | ||
expect((await next.fetch('/dynamic/0')).status).toBe(200) | ||
expect((await next.fetch('/dynamic/1')).status).toBe(200) | ||
const pageRes0 = await next.fetch('dynamic/0') | ||
const pageRes1 = await next.fetch('dynamic/1') | ||
expect(pageRes0.status).toBe(200) | ||
expect(pageRes1.status).toBe(200) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.