-
Notifications
You must be signed in to change notification settings - Fork 177
Description
We have an issue with trailing slashes, see opennextjs/opennextjs-cloudflare#312
The reason why this doesn't work is this code:
opennextjs-aws/packages/open-next/src/core/routing/matcher.ts
Lines 258 to 269 in 14b8182
| const url = new URL(event.url, "http://localhost"); | |
| const emptyBody = emptyReadableStream(); | |
| if ( | |
| // Someone is trying to redirect to a different origin, let's not do that | |
| url.host !== "localhost" || | |
| NextConfig.skipTrailingSlashRedirect || | |
| // We should not apply trailing slash redirect to API routes | |
| event.rawPath.startsWith("/api/") | |
| ) { | |
| return false; | |
| } |
in cloudflare, event.url is http://localhost:8787/... so url.host !== "localhost" is true (the host is localhost:8787).
I think that event.url is not usually an URL but a path in @opennextjs/aws.
However in @opennextjs/cloudflare, event.url is actually an URL.
See also this code in cloudflare-node.ts:
opennextjs-aws/packages/open-next/src/overrides/wrappers/cloudflare-node.ts
Lines 33 to 38 in 14b8182
| // TODO: | |
| // The edge converter populate event.url with the url including the origin. | |
| // This is required for middleware to keep track of the protocol (i.e. http with wrangler dev). | |
| // However the server expects that the origin is not included. | |
| const url = new URL(internalEvent.url); | |
| (internalEvent.url as string) = url.href.slice(url.origin.length); |
@conico974 do you have an idea on how to best fix this?
Thanks!