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) {
<${input.loading}/> - - $!{``} + $!{``} - - $ out.script(`((e,t,d)=>{t=document.getElementById(e);do{t.removeChild(d=t.firstChild)}while(d.data!==e)})(${JSON.stringify(component.id)});`); + $ out.script( + `((e,t,d)=>{t=document.getElementById(e);do{t.removeChild(d=t.firstChild)}while(d.data!==e)})(${JSON.stringify(component.id)});`, + ); @@ -100,7 +117,7 @@ static async function fetchStream(input, out) { <@catch|err|> - + <${input.catch}(err)/> diff --git a/src/node_modules/@internal/micro-frame-slot-component/node.marko b/src/node_modules/@internal/micro-frame-slot-component/node.marko index 39c0642..ba7d801 100644 --- a/src/node_modules/@internal/micro-frame-slot-component/node.marko +++ b/src/node_modules/@internal/micro-frame-slot-component/node.marko @@ -24,7 +24,7 @@ $ { <@catch|e|> $ finishLoading && finishLoading(); - + <${input.catch}(e)/> diff --git a/src/node_modules/@internal/stream-source-component/node.marko b/src/node_modules/@internal/stream-source-component/node.marko index 126c2f2..b4df122 100644 --- a/src/node_modules/@internal/stream-source-component/node.marko +++ b/src/node_modules/@internal/stream-source-component/node.marko @@ -1,9 +1,13 @@ import fetch from "make-fetch-happen"; +import https from "https"; import path from "path"; import { getSource } from "../../../util/stream"; - +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 }); +} $ const request = async () => { const global = out.global; let origin; @@ -12,58 +16,79 @@ $ const request = async () => { 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 res = await (input.fetch || fetch)(url, { - cachePath, - cache: input.cache, - strictSSL: process.env.NODE_TLS_REJECT_UNAUTHORIZED !== "0", - headers: { - ...incomingHeaders, - ...input.headers - } - }) + const { cache } = input; + const headers = { + ...incomingHeaders, + ...input.headers, + }; + const res = await (input.fetch + ? input.fetch( + url, + { + cache, + headers, + }, + internalFetch, + ) + : fetch(url, { + cache, + headers, + ca, + cachePath, + strictSSL, + })); if (!res.ok) throw new Error(res.statusText); return res; -} - +}; $ const streamSource = getSource(input.name, out);
$ out.bf("@_", component, true); <@then|{ body }|> - + <@catch|err|> $ streamSource.close(err); @@ -75,4 +100,3 @@ $ const streamSource = getSource(input.name, out); $ out.ef();
-