diff --git a/src/node_modules/@internal/micro-frame-component/node.marko b/src/node_modules/@internal/micro-frame-component/node.marko index 6a4cdd6..3cc8c7d 100644 --- a/src/node_modules/@internal/micro-frame-component/node.marko +++ b/src/node_modules/@internal/micro-frame-component/node.marko @@ -22,7 +22,9 @@ static async function fetchStream(input, out) { incomingHeaders = Object.fromEntries(request.headers); - origin = url.origin; + const forwardedProto = request.headers.get("x-forwarded-proto"); + const forwardedHost = request.headers.get("x-forwarded-host"); + origin = forwardedHost && forwardedProto ? `${forwardedProto}://${forwardedHost}` : url.origin; } else { const incomingMessage = out.stream && (out.stream.req || out.stream.request) || out.global.req || out.global.request; if (!incomingMessage) { @@ -30,7 +32,13 @@ static async function fetchStream(input, out) { } incomingHeaders = incomingMessage.headers; - origin = `${incomingMessage.protocol}://${incomingHeaders.host}`; + const protocol = + incomingHeaders["x-forwarded-proto"] || + incomingMessage.protocol; + const host = + incomingHeaders["x-forwarded-host"] || + incomingHeaders.host; + origin = `${protocol}://${host}`; } diff --git a/src/node_modules/@internal/stream-source-component/node.marko b/src/node_modules/@internal/stream-source-component/node.marko index e4b0d95..126c2f2 100644 --- a/src/node_modules/@internal/stream-source-component/node.marko +++ b/src/node_modules/@internal/stream-source-component/node.marko @@ -22,7 +22,9 @@ $ const request = async () => { incomingHeaders = Object.fromEntries(request.headers); - origin = url.origin; + const forwardedProto = request.headers.get("x-forwarded-proto"); + const forwardedHost = request.headers.get("x-forwarded-host"); + origin = forwardedHost && forwardedProto ? `${forwardedProto}://${forwardedHost}` : url.origin; } else { const incomingMessage = out.stream && (out.stream.req || out.stream.request) || out.global.req || out.global.request; if (!incomingMessage) { @@ -30,7 +32,13 @@ $ const request = async () => { } incomingHeaders = incomingMessage.headers; - origin = `${incomingMessage.protocol}://${incomingHeaders.host}`; + const protocol = + incomingHeaders["x-forwarded-proto"] || + incomingMessage.protocol; + const host = + incomingHeaders["x-forwarded-host"] || + incomingHeaders.host; + origin = `${protocol}://${host}`; } const url = new URL(input.src, origin);