feat: add a proxy option into settings
This commit is contained in:
@@ -22,6 +22,7 @@ import routes from '@server/routes';
|
||||
import avatarproxy from '@server/routes/avatarproxy';
|
||||
import imageproxy from '@server/routes/imageproxy';
|
||||
import { getAppVersion } from '@server/utils/appVersion';
|
||||
import bindHttpMethod from '@server/utils/bindHttpMethod';
|
||||
import restartFlag from '@server/utils/restartFlag';
|
||||
import { getClientIp } from '@supercharge/request-ip';
|
||||
import { TypeormStore } from 'connect-typeorm/out';
|
||||
@@ -32,6 +33,9 @@ import express from 'express';
|
||||
import * as OpenApiValidator from 'express-openapi-validator';
|
||||
import type { Store } from 'express-session';
|
||||
import session from 'express-session';
|
||||
import http from 'http';
|
||||
import https from 'https';
|
||||
import { HttpsProxyAgent } from 'https-proxy-agent';
|
||||
import next from 'next';
|
||||
import dns from 'node:dns';
|
||||
import net from 'node:net';
|
||||
@@ -67,6 +71,25 @@ app
|
||||
const settings = await getSettings().load();
|
||||
restartFlag.initializeSettings(settings.main);
|
||||
|
||||
// Register HTTP proxy
|
||||
if (settings.main.httpProxy) {
|
||||
const agent = new HttpsProxyAgent(settings.main.httpProxy);
|
||||
|
||||
(globalThis as any)[Symbol.for('undici.globalDispatcher.1')] = agent;
|
||||
|
||||
http.globalAgent = agent;
|
||||
https.globalAgent = agent;
|
||||
|
||||
const httpGet = http.get;
|
||||
const httpRequest = http.request;
|
||||
const httpsGet = https.get;
|
||||
const httpsRequest = https.request;
|
||||
http.get = bindHttpMethod(httpGet, agent);
|
||||
http.request = bindHttpMethod(httpRequest, agent);
|
||||
https.get = bindHttpMethod(httpsGet, agent);
|
||||
https.request = bindHttpMethod(httpsRequest, agent);
|
||||
}
|
||||
|
||||
// Migrate library types
|
||||
if (
|
||||
settings.plex.libraries.length > 1 &&
|
||||
|
||||
@@ -119,6 +119,7 @@ export interface MainSettings {
|
||||
mediaServerType: number;
|
||||
partialRequestsEnabled: boolean;
|
||||
locale: string;
|
||||
httpProxy: string;
|
||||
}
|
||||
|
||||
interface PublicSettings {
|
||||
@@ -325,6 +326,7 @@ class Settings {
|
||||
mediaServerType: MediaServerType.NOT_CONFIGURED,
|
||||
partialRequestsEnabled: true,
|
||||
locale: 'en',
|
||||
httpProxy: '',
|
||||
},
|
||||
plex: {
|
||||
name: '',
|
||||
|
||||
@@ -13,7 +13,8 @@ class RestartFlag {
|
||||
|
||||
return (
|
||||
this.settings.csrfProtection !== settings.csrfProtection ||
|
||||
this.settings.trustProxy !== settings.trustProxy
|
||||
this.settings.trustProxy !== settings.trustProxy ||
|
||||
this.settings.httpProxy !== settings.httpProxy
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user