Skip to content

Commit

Permalink
Correct param gathering in fallback mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Oct 16, 2020
1 parent 52b6f51 commit 533de64
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/next/build/webpack/loaders/next-serverless-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ const nextServerlessLoader: loader.Loader = function () {
let localeDomainRedirect
const localePathResult = normalizeLocalePath(parsedUrl.pathname, i18n.locales)
routeNoAssetPath = normalizeLocalePath(routeNoAssetPath, i18n.locales).pathname
if (localePathResult.detectedLocale) {
detectedLocale = localePathResult.detectedLocale
req.url = formatUrl({
Expand Down Expand Up @@ -337,6 +339,7 @@ const nextServerlessLoader: loader.Loader = function () {
res.end()
return
}
detectedLocale = detectedLocale || defaultLocale
`
: `
Expand Down Expand Up @@ -547,10 +550,10 @@ const nextServerlessLoader: loader.Loader = function () {
if (parsedUrl.pathname.match(/_next\\/data/)) {
const {
default: getrouteNoAssetPath,
default: getRouteNoAssetPath,
} = require('next/dist/next-server/lib/router/utils/get-route-from-asset-path');
_nextData = true;
parsedUrl.pathname = getrouteNoAssetPath(
parsedUrl.pathname = getRouteNoAssetPath(
parsedUrl.pathname.replace(
new RegExp('/_next/data/${escapedBuildId}/'),
'/'
Expand Down Expand Up @@ -609,12 +612,24 @@ const nextServerlessLoader: loader.Loader = function () {
? `const nowParams = req.headers && req.headers["x-now-route-matches"]
? getRouteMatcher(
(function() {
const { re, groups } = getRouteRegex("${page}");
const { re, groups, routeKeys } = getRouteRegex("${page}");
return {
re: {
// Simulate a RegExp match from the \`req.url\` input
exec: str => {
const obj = parseQs(str);
// favor named matches if available
const routeKeyNames = Object.keys(routeKeys)
if (routeKeyNames.every(name => obj[name])) {
return routeKeyNames.reduce((prev, keyName) => {
const paramName = routeKeys[keyName]
prev[groups[paramName].pos] = obj[keyName]
return prev
}, {})
}
return Object.keys(obj).reduce(
(prev, key) =>
Object.assign(prev, {
Expand Down

0 comments on commit 533de64

Please sign in to comment.