mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 14:40:23 +08:00
perf: lazy require dependencies (#8025)
This commit is contained in:
@@ -1,17 +1,20 @@
|
||||
const config = require('@/config').value;
|
||||
const HttpsProxyAgent = require('https-proxy-agent');
|
||||
const SocksProxyAgent = require('socks-proxy-agent');
|
||||
const tunnel = require('tunnel');
|
||||
const logger = require('./logger');
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
|
||||
let tunnel;
|
||||
let HttpsProxyAgent;
|
||||
let SocksProxyAgent;
|
||||
|
||||
let agent = null;
|
||||
if (config.proxyUri && typeof config.proxyUri === 'string') {
|
||||
let proxy = null;
|
||||
if (config.proxyUri.startsWith('http')) {
|
||||
HttpsProxyAgent = HttpsProxyAgent || require('https-proxy-agent');
|
||||
proxy = new HttpsProxyAgent(config.proxyUri);
|
||||
} else if (config.proxyUri.startsWith('socks')) {
|
||||
SocksProxyAgent = SocksProxyAgent || require('socks-proxy-agent');
|
||||
proxy = new SocksProxyAgent(config.proxyUri);
|
||||
} else {
|
||||
throw 'Unknown proxy-uri format';
|
||||
@@ -27,10 +30,12 @@ if (config.proxyUri && typeof config.proxyUri === 'string') {
|
||||
|
||||
switch (config.proxy.protocol) {
|
||||
case 'socks':
|
||||
SocksProxyAgent = SocksProxyAgent || require('socks-proxy-agent');
|
||||
agent.http = new SocksProxyAgent(proxyUrl);
|
||||
agent.https = new SocksProxyAgent(proxyUrl);
|
||||
break;
|
||||
case 'http':
|
||||
tunnel = tunnel || require('tunnel');
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
|
||||
agent.http = tunnel.httpOverHttp({
|
||||
proxy: {
|
||||
@@ -46,6 +51,7 @@ if (config.proxyUri && typeof config.proxyUri === 'string') {
|
||||
});
|
||||
break;
|
||||
case 'https':
|
||||
tunnel = tunnel || require('tunnel');
|
||||
agent.http = tunnel.httpOverHttps({
|
||||
proxy: {
|
||||
host: config.proxy.host,
|
||||
|
||||
Reference in New Issue
Block a user