mirror of https://github.com/certd/certd
chore:
parent
8b8039f42b
commit
0451fa7573
|
@ -17,6 +17,8 @@
|
||||||
"@certd/plus": "1.22.1",
|
"@certd/plus": "1.22.1",
|
||||||
"axios": "^1.7.2",
|
"axios": "^1.7.2",
|
||||||
"fix-path": "^4.0.0",
|
"fix-path": "^4.0.0",
|
||||||
|
"http-proxy-agent": "^7.0.2",
|
||||||
|
"https-proxy-agent": "^7.0.5",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"node-forge": "^1.3.1",
|
"node-forge": "^1.3.1",
|
||||||
"nodemailer": "^6.9.3",
|
"nodemailer": "^6.9.3",
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import axios, { AxiosRequestConfig } from "axios";
|
import axios, { AxiosRequestConfig } from "axios";
|
||||||
import { logger } from "./util.log.js";
|
import { logger } from "./util.log.js";
|
||||||
import { Logger } from "log4js";
|
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 {
|
export class HttpError extends Error {
|
||||||
status?: number;
|
status?: number;
|
||||||
statusText?: string;
|
statusText?: string;
|
||||||
|
@ -45,7 +47,7 @@ export function createAxiosService({ logger }: { logger: Logger }) {
|
||||||
// 创建一个 axios 实例
|
// 创建一个 axios 实例
|
||||||
const service = axios.create();
|
const service = axios.create();
|
||||||
|
|
||||||
// const defaultAgents = createAgent();
|
const defaultAgents = createAgent();
|
||||||
// 请求拦截
|
// 请求拦截
|
||||||
service.interceptors.request.use(
|
service.interceptors.request.use(
|
||||||
(config: any) => {
|
(config: any) => {
|
||||||
|
@ -53,14 +55,14 @@ export function createAxiosService({ logger }: { logger: Logger }) {
|
||||||
if (config.timeout == null) {
|
if (config.timeout == null) {
|
||||||
config.timeout = 15000;
|
config.timeout = 15000;
|
||||||
}
|
}
|
||||||
// let agents = defaultAgents;
|
let agents = defaultAgents;
|
||||||
// if (config.skipSslVerify) {
|
if (config.skipSslVerify) {
|
||||||
// logger.info("跳过SSL验证");
|
logger.info("跳过SSL验证");
|
||||||
// agents = createAgent({ rejectUnauthorized: config.rejectUnauthorized });
|
agents = createAgent({ rejectUnauthorized: false } as any);
|
||||||
// }
|
}
|
||||||
// delete config.skipSslVerify;
|
delete config.skipSslVerify;
|
||||||
// config.httpsAgent = agents.httpsAgent;
|
config.httpsAgent = agents.httpsAgent;
|
||||||
// config.httpAgent = agents.httpAgent;
|
config.httpAgent = agents.httpAgent;
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
},
|
},
|
||||||
|
@ -139,10 +141,19 @@ export type HttpClient = {
|
||||||
request<D = any, R = any>(config: HttpRequestConfig<D>): Promise<HttpClientResponse<R>>;
|
request<D = any, R = any>(config: HttpRequestConfig<D>): Promise<HttpClientResponse<R>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function createAgent(opts: ProxyAgentOptions = {}) {
|
export function createAgent(opts: nodeHttp.AgentOptions = {}) {
|
||||||
const httpAgent = new ProxyAgent(opts);
|
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 {
|
return {
|
||||||
httpAgent,
|
httpAgent,
|
||||||
httpsAgent: httpAgent,
|
httpsAgent,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"nanoid": "^4.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-commonjs": "^23.0.4",
|
"@rollup/plugin-commonjs": "^23.0.4",
|
||||||
|
|
Loading…
Reference in New Issue