Unverified Commit 8e216ecb authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix locale domain public files check (#60749)

This ensures we properly handle serving public files when routing via a
locale domain and adds regression tests for this case.

Closes: https://github.com/vercel/next.js/issues/54765
Closes: https://github.com/vercel/next.js/pull/59773
Closes: https://github.com/vercel/next.js/pull/55137
Closes NEXT-2123
parent 8d4e5be7
......@@ -472,7 +472,13 @@ export async function setupFsCheck(opts: {
itemPath,
// legacy behavior allows visiting static assets under
// default locale but no other locale
isDynamicOutput ? undefined : [i18n?.defaultLocale]
isDynamicOutput
? undefined
: [
i18n?.defaultLocale,
// default locales from domains need to be matched too
...(i18n.domains?.map((item) => item.defaultLocale) || []),
]
)
if (localeResult.pathname !== curItemPath) {
......
......@@ -26,6 +26,7 @@ export const nonDomainLocales = [
'fr',
'en',
]
const defaultLocales = ['en-US', 'do', 'go']
export const locales = [...nonDomainLocales, ...domainLocales]
async function addDefaultLocaleCookie(browser) {
......@@ -72,7 +73,7 @@ export function runTests(ctx) {
{ redirect: 'manual' }
)
if (locale !== 'en-US') {
if (!defaultLocales.includes(locale)) {
expect(res.status).toBe(404)
expect(await res.text()).toContain('could not be found')
} else {
......@@ -83,6 +84,23 @@ export function runTests(ctx) {
}
})
it('should serve public file on locale domain', async () => {
for (const host of ['example.do', 'example.com']) {
const res = await fetchViaHTTP(
ctx.appPort,
`${ctx.basePath || ''}/files/texts/file.txt`,
undefined,
{
headers: {
host,
},
}
)
expect(res.status).toBe(200)
expect(await res.text()).toContain('hello from file.txt')
}
})
it('should 404 for locale prefixed public folder files', async () => {
for (const locale of locales) {
const res = await fetchViaHTTP(
......@@ -92,7 +110,7 @@ export function runTests(ctx) {
{ redirect: 'manual' }
)
if (locale !== 'en-US') {
if (!defaultLocales.includes(locale)) {
expect(res.status).toBe(404)
expect(await res.text()).toContain('could not be found')
} else {
......
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