diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-404/renders.expected/loading.1.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-404/renders.expected/loading.1.html index 5f89f6d..e6fb739 100644 --- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-404/renders.expected/loading.1.html +++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-404/renders.expected/loading.1.html @@ -15,6 +15,6 @@ id="GENERATED-2" > \ No newline at end of file diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-404/renders.expected/loading.3.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-404/renders.expected/loading.3.html index 03950f9..9c242c7 100644 --- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-404/renders.expected/loading.3.html +++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-404/renders.expected/loading.3.html @@ -22,6 +22,6 @@ id="GENERATED-3" > \ No newline at end of file diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-behind-reorder/renders.expected/loading.1.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-behind-reorder/renders.expected/loading.1.html index 02965f0..879b9db 100644 --- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-behind-reorder/renders.expected/loading.1.html +++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-behind-reorder/renders.expected/loading.1.html @@ -26,7 +26,7 @@ id="GENERATED-5" > \ No newline at end of file diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-behind-reorder/renders.expected/loading.3.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-behind-reorder/renders.expected/loading.3.html index ea062bc..e50b87a 100644 --- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-behind-reorder/renders.expected/loading.3.html +++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-behind-reorder/renders.expected/loading.3.html @@ -33,7 +33,7 @@ id="GENERATED-6" > \ No newline at end of file diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-timeout/renders.expected/loading.2.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-timeout/renders.expected/loading.2.html index 9732bd4..e66122d 100644 --- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-timeout/renders.expected/loading.2.html +++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-timeout/renders.expected/loading.2.html @@ -18,6 +18,6 @@ test_html for slot_1
\ No newline at end of file diff --git a/src/node_modules/@internal/micro-frame-component/node.marko b/src/node_modules/@internal/micro-frame-component/node.marko index 3cc8c7d..280f2c8 100644 --- a/src/node_modules/@internal/micro-frame-component/node.marko +++ b/src/node_modules/@internal/micro-frame-component/node.marko @@ -1,9 +1,12 @@ import path from "path"; +import https from "https"; import fetch from "make-fetch-happen"; - +static const { ca } = https.globalAgent.options; static const cachePath = path.resolve("node_modules/.cache/fetch"); static const strictSSL = process.env.NODE_TLS_REJECT_UNAUTHORIZED !== "0"; - +static function internalFetch(url, options) { + return fetch(url, { ...options, ca, cachePath, strictSSL }); +} static async function fetchStream(input, out) { const global = out.global; let origin; @@ -12,36 +15,43 @@ static async function fetchStream(input, out) { if (global.platform) { const url = global.url; if (!url) { - throw new Error("Please assign $global.platform.url with WHATWG URL object compatible with @marko/run."); + throw new Error( + "Please assign $global.platform.url with WHATWG URL object compatible with @marko/run.", + ); } const request = global.request; if (!request || !request.headers) { - throw new Error("Please assign $global.platform.request with WHATWG request object compatible with @marko/run."); + throw new Error( + "Please assign $global.platform.request with WHATWG request object compatible with @marko/run.", + ); } - incomingHeaders = Object.fromEntries(request.headers); const forwardedProto = request.headers.get("x-forwarded-proto"); const forwardedHost = request.headers.get("x-forwarded-host"); - origin = forwardedHost && forwardedProto ? `${forwardedProto}://${forwardedHost}` : url.origin; + origin = + forwardedHost && forwardedProto + ? `${forwardedProto}://${forwardedHost}` + : url.origin; } else { - const incomingMessage = out.stream && (out.stream.req || out.stream.request) || out.global.req || out.global.request; + const incomingMessage = + (out.stream && (out.stream.req || out.stream.request)) || + out.global.req || + out.global.request; if (!incomingMessage) { - throw new Error("Could not get request from stream/global. Please assign out.global.req with proper request object."); + throw new Error( + "Could not get request from stream/global. Please assign out.global.req with proper request object.", + ); } incomingHeaders = incomingMessage.headers; const protocol = - incomingHeaders["x-forwarded-proto"] || - incomingMessage.protocol; - const host = - incomingHeaders["x-forwarded-host"] || - incomingHeaders.host; + incomingHeaders["x-forwarded-proto"] || incomingMessage.protocol; + const host = incomingHeaders["x-forwarded-host"] || incomingHeaders.host; origin = `${protocol}://${host}`; } - const url = new URL(input.src, origin); const { cache } = input; const headers = { @@ -51,14 +61,21 @@ static async function fetchStream(input, out) { }; const res = await (input.fetch - ? input.fetch(url, { cache, headers }, fetch) + ? input.fetch( + url, + { + cache, + headers, + }, + internalFetch, + ) : fetch(url, { - cache, - headers, - cachePath, - strictSSL, - }) - ); + cache, + headers, + ca, + cachePath, + strictSSL, + })); if (!res.ok) throw new Error(res.statusText); @@ -72,10 +89,8 @@ static async function fetchStream(input, out) {