mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
perf: 支持cloudflare域名
This commit is contained in:
@@ -119,6 +119,7 @@ module.exports = async function(client, userOpts) {
|
||||
try {
|
||||
recordItem = await opts.challengeCreateFn(authz, challenge, keyAuthorization);
|
||||
|
||||
// throw new Error('测试异常');
|
||||
/* Challenge verification */
|
||||
if (opts.skipChallengeVerification === true) {
|
||||
log(`[auto] [${d}] Skipping challenge verification since skipChallengeVerification=true`);
|
||||
@@ -177,30 +178,43 @@ module.exports = async function(client, userOpts) {
|
||||
});
|
||||
|
||||
|
||||
// let promise = Promise.resolve();
|
||||
// function runPromisesSerially(tasks) {
|
||||
// tasks.forEach((task) => {
|
||||
// promise = promise.then(task);
|
||||
// });
|
||||
// return promise;
|
||||
// }
|
||||
|
||||
function runPromiseParallel(tasks) {
|
||||
return Promise.all(tasks.map((task) => task()));
|
||||
function runAllPromise(tasks) {
|
||||
let promise = Promise.resolve();
|
||||
tasks.forEach((task) => {
|
||||
promise = promise.then(task);
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
// function runPromisePa(tasks) {
|
||||
// return Promise.all(tasks.map((task) => task()));
|
||||
// }
|
||||
|
||||
|
||||
try {
|
||||
log('开始challenge');
|
||||
await runPromiseParallel(challengePromises);
|
||||
await runAllPromise(challengePromises);
|
||||
|
||||
log('challenge结束');
|
||||
|
||||
// log('[auto] Waiting for challenge valid status');
|
||||
// await Promise.all(challengePromises);
|
||||
|
||||
/**
|
||||
* Finalize order and download certificate
|
||||
*/
|
||||
|
||||
log('[auto] Finalizing order and downloading certificate');
|
||||
const finalized = await client.finalizeOrder(order, opts.csr);
|
||||
return await client.getCertificate(finalized, opts.preferredChain);
|
||||
}
|
||||
catch (e) {
|
||||
log('challenge失败');
|
||||
log('证书申请失败');
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
log('清理challenge痕迹');
|
||||
await runPromiseParallel(clearTasks);
|
||||
log(`清理challenge痕迹,length:${clearTasks.length}`);
|
||||
await runAllPromise(clearTasks);
|
||||
}
|
||||
|
||||
// try {
|
||||
@@ -210,19 +224,4 @@ module.exports = async function(client, userOpts) {
|
||||
// log('清理challenge');
|
||||
// await Promise.allSettled(clearTasks);
|
||||
// }
|
||||
|
||||
|
||||
log('challenge结束');
|
||||
|
||||
// log('[auto] Waiting for challenge valid status');
|
||||
// await Promise.all(challengePromises);
|
||||
|
||||
|
||||
/**
|
||||
* Finalize order and download certificate
|
||||
*/
|
||||
|
||||
log('[auto] Finalizing order and downloading certificate');
|
||||
const finalized = await client.finalizeOrder(order, opts.csr);
|
||||
return client.getCertificate(finalized, opts.preferredChain);
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ContextFactory, IContext } from "./context";
|
||||
import { IStorage } from "./storage";
|
||||
import { logger } from "../utils/util.log";
|
||||
import { Logger } from "log4js";
|
||||
import { request } from "../utils/util.request";
|
||||
import { createAxiosService } from "../utils/util.request";
|
||||
import { IAccessService } from "../access";
|
||||
import { RegistryItem } from "../registry";
|
||||
import { Decorator } from "../decorator";
|
||||
@@ -213,11 +213,12 @@ export class Executor {
|
||||
}
|
||||
});
|
||||
|
||||
const http = createAxiosService({ logger: currentLogger });
|
||||
const taskCtx: TaskInstanceContext = {
|
||||
pipeline: this.pipeline,
|
||||
step,
|
||||
lastStatus,
|
||||
http: request,
|
||||
http,
|
||||
logger: currentLogger,
|
||||
accessService: this.options.accessService,
|
||||
emailService: this.options.emailService,
|
||||
|
||||
@@ -2,10 +2,11 @@ import axios from "axios";
|
||||
// @ts-ignore
|
||||
import qs from "qs";
|
||||
import { logger } from "./util.log";
|
||||
import { Logger } from "log4js";
|
||||
/**
|
||||
* @description 创建请求实例
|
||||
*/
|
||||
function createService() {
|
||||
export function createAxiosService({ logger }: { logger: Logger }) {
|
||||
// 创建一个 axios 实例
|
||||
const service = axios.create();
|
||||
// 请求拦截
|
||||
@@ -18,18 +19,19 @@ function createService() {
|
||||
}); // 序列化请求参数
|
||||
delete config.formData;
|
||||
}
|
||||
logger.info(`http request:${config.url},method:${config.method}`);
|
||||
return config;
|
||||
},
|
||||
(error: Error) => {
|
||||
// 发送失败
|
||||
logger.error(error);
|
||||
logger.error("接口请求失败:", error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
// 响应拦截
|
||||
service.interceptors.response.use(
|
||||
(response: any) => {
|
||||
logger.info("http response:", JSON.stringify(response.data));
|
||||
logger.info("http response:", JSON.stringify(response?.data));
|
||||
return response.data;
|
||||
},
|
||||
(error: any) => {
|
||||
@@ -48,11 +50,12 @@ function createService() {
|
||||
// case 505: error.message = 'HTTP版本不受支持'; break
|
||||
// default: break
|
||||
// }
|
||||
logger.error("请求出错:", error.response.config.url, error);
|
||||
logger.error(`请求出错:url:${error?.response?.config.url},method:${error.response.config.method},status:${error?.response?.status}`);
|
||||
logger.info("返回数据:", JSON.stringify(error?.response?.data));
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
return service;
|
||||
}
|
||||
|
||||
export const request = createService();
|
||||
export const request = createAxiosService({ logger });
|
||||
|
||||
Reference in New Issue
Block a user