Skip to content

Commit c64941d

Browse files
committed
fix(cloudflare): enable trailiing slash redirect
event.url is a valid URL within cloudflare vs a path otherwise
1 parent f5e2157 commit c64941d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

.changeset/lovely-trains-teach.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
fix(cloudflare): enable trailiing slash redirect

packages/open-next/src/core/routing/matcher.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ export function handleRewrites<T extends RewriteDefinition>(
255255
function handleTrailingSlashRedirect(
256256
event: InternalEvent,
257257
): false | InternalResult {
258-
const url = new URL(event.url, "http://localhost");
259-
const emptyBody = emptyReadableStream();
258+
// When rawPath is `//domain`, `url.host` would be `domain`.
259+
const url = new URL(event.rawPath, "http://localhost");
260260

261261
if (
262262
// Someone is trying to redirect to a different origin, let's not do that
@@ -267,6 +267,9 @@ function handleTrailingSlashRedirect(
267267
) {
268268
return false;
269269
}
270+
271+
const emptyBody = emptyReadableStream();
272+
270273
if (
271274
NextConfig.trailingSlash &&
272275
!event.headers["x-nextjs-data"] &&

0 commit comments

Comments
 (0)