From 0451fa7573bea75cbf043fb67efc685220cd0ea9 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sun, 22 Sep 2024 00:33:09 +0800 Subject: [PATCH] chore: --- packages/core/pipeline/package.json | 2 + .../core/pipeline/src/utils/util.request.ts | 37 ++++++++++++------- packages/libs/lib-iframe/package.json | 1 + 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/packages/core/pipeline/package.json b/packages/core/pipeline/package.json index 963fe489..ad92f09b 100644 --- a/packages/core/pipeline/package.json +++ b/packages/core/pipeline/package.json @@ -17,6 +17,8 @@ "@certd/plus": "1.22.1", "axios": "^1.7.2", "fix-path": "^4.0.0", + "http-proxy-agent": "^7.0.2", + "https-proxy-agent": "^7.0.5", "lodash-es": "^4.17.21", "node-forge": "^1.3.1", "nodemailer": "^6.9.3", diff --git a/packages/core/pipeline/src/utils/util.request.ts b/packages/core/pipeline/src/utils/util.request.ts index ca0c11b9..c098c090 100644 --- a/packages/core/pipeline/src/utils/util.request.ts +++ b/packages/core/pipeline/src/utils/util.request.ts @@ -1,7 +1,9 @@ import axios, { AxiosRequestConfig } from "axios"; import { logger } from "./util.log.js"; import { Logger } from "log4js"; -import { ProxyAgent, ProxyAgentOptions } from "proxy-agent"; +import { HttpProxyAgent } from "http-proxy-agent"; +import { HttpsProxyAgent } from "https-proxy-agent"; +import nodeHttp from "http"; export class HttpError extends Error { status?: number; statusText?: string; @@ -45,7 +47,7 @@ export function createAxiosService({ logger }: { logger: Logger }) { // 创建一个 axios 实例 const service = axios.create(); - // const defaultAgents = createAgent(); + const defaultAgents = createAgent(); // 请求拦截 service.interceptors.request.use( (config: any) => { @@ -53,14 +55,14 @@ export function createAxiosService({ logger }: { logger: Logger }) { if (config.timeout == null) { config.timeout = 15000; } - // let agents = defaultAgents; - // if (config.skipSslVerify) { - // logger.info("跳过SSL验证"); - // agents = createAgent({ rejectUnauthorized: config.rejectUnauthorized }); - // } - // delete config.skipSslVerify; - // config.httpsAgent = agents.httpsAgent; - // config.httpAgent = agents.httpAgent; + let agents = defaultAgents; + if (config.skipSslVerify) { + logger.info("跳过SSL验证"); + agents = createAgent({ rejectUnauthorized: false } as any); + } + delete config.skipSslVerify; + config.httpsAgent = agents.httpsAgent; + config.httpAgent = agents.httpAgent; return config; }, @@ -139,10 +141,19 @@ export type HttpClient = { request(config: HttpRequestConfig): Promise>; }; -export function createAgent(opts: ProxyAgentOptions = {}) { - const httpAgent = new ProxyAgent(opts); +export function createAgent(opts: nodeHttp.AgentOptions = {}) { + let httpAgent, httpsAgent; + const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy; + if (httpProxy) { + httpAgent = new HttpProxyAgent(httpProxy, opts as any); + } + const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy; + if (httpsProxy) { + httpsAgent = new HttpsProxyAgent(httpsProxy, opts as any); + } + return { httpAgent, - httpsAgent: httpAgent, + httpsAgent, }; } diff --git a/packages/libs/lib-iframe/package.json b/packages/libs/lib-iframe/package.json index 7483d506..fa3c9085 100644 --- a/packages/libs/lib-iframe/package.json +++ b/packages/libs/lib-iframe/package.json @@ -13,6 +13,7 @@ "preview": "vite preview" }, "dependencies": { + "nanoid": "^4.0.0" }, "devDependencies": { "@rollup/plugin-commonjs": "^23.0.4",