Skip to content

Commit 69a26e7

Browse files
authored
fix(converters): refactor the constructing of URL in node converter (#867)
* fix in node converter to remove leading forward slashes * changeset * refactor
1 parent d434708 commit 69a26e7

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

.changeset/stale-rivers-invite.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: remove leading forward slashes from url in node converter

packages/open-next/src/overrides/converters/node.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { Converter } from "types/overrides";
66
import { extractHostFromHeaders, getQueryFromSearchParams } from "./utils.js";
77

88
const converter: Converter = {
9-
convertFrom: async (req: IncomingMessage) => {
9+
convertFrom: async (req: IncomingMessage & { protocol?: string }) => {
1010
const body = await new Promise<Buffer>((resolve) => {
1111
const chunks: Uint8Array[] = [];
1212
req.on("data", (chunk) => {
@@ -25,7 +25,10 @@ const converter: Converter = {
2525
])
2626
.filter(([key]) => key),
2727
);
28-
const url = new URL(req.url!, `http://${extractHostFromHeaders(headers)}`);
28+
// https://nodejs.org/api/http.html#messageurl
29+
const url = new URL(
30+
`${req.protocol ? req.protocol : "http"}://${extractHostFromHeaders(headers)}${req.url}`,
31+
);
2932
const query = getQueryFromSearchParams(url.searchParams);
3033
return {
3134
type: "core",

0 commit comments

Comments
 (0)