Skip to content

Commit dd9face

Browse files
vicbconico974
andauthored
fix(cloudflare): enable trailing slash redirect (#722)
Co-authored-by: conico974 <nicodorseuil@yahoo.fr>
1 parent f5e2157 commit dd9face

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@ 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+
// https://github.com/opennextjs/opennextjs-aws/issues/355
260+
const url = new URL(event.rawPath, "http://localhost");
260261

261262
if (
262263
// Someone is trying to redirect to a different origin, let's not do that
@@ -267,6 +268,9 @@ function handleTrailingSlashRedirect(
267268
) {
268269
return false;
269270
}
271+
272+
const emptyBody = emptyReadableStream();
273+
270274
if (
271275
NextConfig.trailingSlash &&
272276
!event.headers["x-nextjs-data"] &&

0 commit comments

Comments
 (0)