Added PROXY_TRUST_CA
This commit is contained in:
@@ -42,13 +42,9 @@ export const fetchProxied = async (
|
|||||||
const nonProxiedUrl =
|
const nonProxiedUrl =
|
||||||
requestInput instanceof Request ? requestInput.url : requestInput.toString();
|
requestInput instanceof Request ? requestInput.url : requestInput.toString();
|
||||||
|
|
||||||
console.log('nonProxiedUrl', nonProxiedUrl);
|
|
||||||
|
|
||||||
if (needsProxying(nonProxiedUrl)) {
|
if (needsProxying(nonProxiedUrl)) {
|
||||||
const proxiedUrl = corsProxyUrl + encodeUrl(nonProxiedUrl);
|
const proxiedUrl = corsProxyUrl + encodeUrl(nonProxiedUrl);
|
||||||
|
|
||||||
console.log('proxiedUrl', proxiedUrl);
|
|
||||||
|
|
||||||
if (requestInput instanceof Request) {
|
if (requestInput instanceof Request) {
|
||||||
requestInput = new Request(proxiedUrl, {
|
requestInput = new Request(proxiedUrl, {
|
||||||
method: requestInput.method,
|
method: requestInput.method,
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { isOwnBackend } from '$lib/shared';
|
import { isOwnBackend } from '$lib/shared';
|
||||||
import { env } from '$env/dynamic/public';
|
import { env } from '$env/dynamic/public';
|
||||||
import { env as privateEnv } from '$env/dynamic/private';
|
import { env as privateEnv } from '$env/dynamic/private';
|
||||||
|
import { Agent } from 'undici';
|
||||||
|
import fs from 'fs';
|
||||||
|
import tls from 'tls';
|
||||||
|
|
||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import { parse as tldParse } from 'tldts';
|
import { parse as tldParse } from 'tldts';
|
||||||
@@ -59,6 +62,19 @@ for (const dynamicDomain of dynamicAllowDomainsEnvVars) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let dispatcher: Agent;
|
||||||
|
|
||||||
|
const certPath = privateEnv.PROXY_TRUST_CA;
|
||||||
|
if (certPath && fs.existsSync(certPath)) {
|
||||||
|
dispatcher = new Agent({
|
||||||
|
connect: {
|
||||||
|
ca: [fs.readFileSync(certPath), ...tls.rootCertificates]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dispatcher = new Agent();
|
||||||
|
}
|
||||||
|
|
||||||
async function proxyRequest(
|
async function proxyRequest(
|
||||||
request: Request,
|
request: Request,
|
||||||
urlToProxy: string,
|
urlToProxy: string,
|
||||||
@@ -145,7 +161,9 @@ async function proxyRequest(
|
|||||||
response = await fetch(urlToProxyObj.toString(), {
|
response = await fetch(urlToProxyObj.toString(), {
|
||||||
...requestOptions,
|
...requestOptions,
|
||||||
body,
|
body,
|
||||||
signal: AbortSignal.timeout(10000)
|
signal: AbortSignal.timeout(10000),
|
||||||
|
// @ts-expect-error Node-specific option
|
||||||
|
dispatcher
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errorMsg = (err as any).toString();
|
errorMsg = (err as any).toString();
|
||||||
|
|||||||
Reference in New Issue
Block a user