Skip to content

Make event.url consistent across platforms (URL vs path) #719

Closed
@vicb

Description

@vicb

We have an issue with trailing slashes, see opennextjs/opennextjs-cloudflare#312

The reason why this doesn't work is this code:

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:

// 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions