Files
Termix/electron/remote-sync-fetch.cjs
T

28 lines
884 B
JavaScript
Raw Normal View History

+17
2026-09-20 14:56:39 -05:00
const { Agent, fetch: undiciFetch } = require("undici");
function createRemoteSyncFetch(getConfig) {
let invalidCertificateAgent;
return function fetchRemoteSync(url, options = {}) {
const config = getConfig();
const target = new URL(url);
const allowInvalidCertificate =
config?.allowInvalidCertificate === true &&
config.serverUrl &&
target.protocol === "https:" &&
target.origin === new URL(config.serverUrl).origin;
if (!allowInvalidCertificate) return fetch(url, options);
invalidCertificateAgent ??= new Agent({
connect: { rejectUnauthorized: false },
});
return undiciFetch(url, {
...options,
dispatcher: invalidCertificateAgent,
// A redirected request must not inherit the configured origin's TLS exception.
redirect: "error",
});
};
}
module.exports = { createRemoteSyncFetch };