diff --git a/.changeset/chilled-ties-lay.md b/.changeset/chilled-ties-lay.md new file mode 100644 index 0000000000000..90269781e66c8 --- /dev/null +++ b/.changeset/chilled-ties-lay.md @@ -0,0 +1,10 @@ +--- +"wrangler": patch +--- + +fix: ensure pages routes are defined correctly + +In e151223 we introduced a bug where the RouteKey was now an array rather than a simple URL string. When it got stringified into the routing object these were invalid. +E.g. `[':page*', undefined]` got stringified to `":page*,"` rather than `":page*"`. + +Fixes #379 diff --git a/packages/wrangler/pages/functions/filepath-routing.ts b/packages/wrangler/pages/functions/filepath-routing.ts index c8dd322538987..dbf53f36fb28e 100644 --- a/packages/wrangler/pages/functions/filepath-routing.ts +++ b/packages/wrangler/pages/functions/filepath-routing.ts @@ -155,7 +155,14 @@ export async function generateConfigFromFileTree({ routeEntries.sort(([a], [b]) => compareRoutes(a, b)); - return { routes: Object.fromEntries(routeEntries) } as Config; + return { + routes: Object.fromEntries( + routeEntries.map(([routeKey, routeConfig]) => [ + stringifyRouteKey(routeKey), + routeConfig, + ]) + ), + } as Config; } // Ensure routes are produced in order of precedence so that @@ -229,3 +236,7 @@ interface NonEmptyArray extends Array { function isNotEmpty(array: T[]): array is NonEmptyArray { return array.length > 0; } + +function stringifyRouteKey(routeKey: RouteKey): string { + return (routeKey[1] ? `${routeKey[1]} ` : "") + routeKey[0]; +}