Skip to content

Commit ee3a48e

Browse files
committed
fix: pass only first language to next-server to match platform redirects support
1 parent dcb5eb8 commit ee3a48e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/runtime/src/templates/getHandler.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ const makeHandler = ({ conf, app, pageRoot, NextServer, staticManifest = [], mod
130130
const query = new URLSearchParams(event.queryStringParameters).toString()
131131
event.path = query ? `${event.path}?${query}` : event.path
132132

133+
if (event.headers['accept-language']) {
134+
// keep just first language to match Netlify redirect limitation:
135+
// https://docs.netlify.com/routing/redirects/redirect-options/#redirect-by-country-or-language
136+
// > Language-based redirects always match against the first language reported by the browser in the Accept-Language header regardless of quality value weighting.
137+
// If we wouldn't keep just first language, it's possible for `next-server` to generate locale redirect that could be cached by ODB
138+
event.headers['accept-language'] = event.headers['accept-language'].replace(/\s*,.*$/, '')
139+
}
140+
133141
const { headers, ...result } = await getBridge(event, context).launcher(event, context)
134142

135143
// Convert all headers to multiValueHeaders

0 commit comments

Comments
 (0)