Skip to content

Commit

Permalink
fix: ensure pages routes are defined correctly
Browse files Browse the repository at this point in the history
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
  • Loading branch information
petebacondarwin committed Feb 3, 2022
1 parent d3bb3b4 commit 6233b40
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .changeset/chilled-ties-lay.md
Original file line number Diff line number Diff line change
@@ -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
13 changes: 12 additions & 1 deletion packages/wrangler/pages/functions/filepath-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -229,3 +236,7 @@ interface NonEmptyArray<T> extends Array<T> {
function isNotEmpty<T>(array: T[]): array is NonEmptyArray<T> {
return array.length > 0;
}

function stringifyRouteKey(routeKey: RouteKey): string {
return (routeKey[1] ? `${routeKey[1]} ` : "") + routeKey[0];
}

0 comments on commit 6233b40

Please sign in to comment.