Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix locale domain public files check #60749

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/next/src/server/lib/router-utils/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 20 additions & 2 deletions test/integration/i18n-support/test/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const nonDomainLocales = [
'fr',
'en',
]
const defaultLocales = ['en-US', 'do', 'go']
export const locales = [...nonDomainLocales, ...domainLocales]

async function addDefaultLocaleCookie(browser) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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(
Expand All @@ -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 {
Expand Down