fix: 修复启动时自签证书无法保存的bug

pull/229/head
xiaojunnuo 2024-10-26 23:24:26 +08:00
parent abd2dcf2e8
commit 526c48450b
4 changed files with 21 additions and 21 deletions

View File

@ -8,7 +8,7 @@ function createAgent(opts = {}) {
let httpAgent;
let
httpsAgent;
const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy;
const httpProxy = opts.httpProxy || process.env.HTTP_PROXY || process.env.http_proxy;
if (httpProxy) {
log(`acme use httpProxy:${httpProxy}`);
httpAgent = new HttpProxyAgent(httpProxy, opts);
@ -16,7 +16,7 @@ function createAgent(opts = {}) {
else {
httpAgent = new nodeHttp.Agent(opts);
}
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
const httpsProxy = opts.httpsProxy || process.env.HTTPS_PROXY || process.env.https_proxy;
if (httpsProxy) {
log(`acme use httpsProxy:${httpsProxy}`);
httpsAgent = new HttpsProxyAgent(httpsProxy, opts);
@ -38,14 +38,7 @@ function getGlobalAgents() {
function setGlobalProxy(opts) {
log('acme setGlobalProxy:', opts);
if (opts.httpProxy) {
process.env.HTTP_PROXY = opts.httpProxy;
}
if (opts.httpsProxy) {
process.env.HTTPS_PROXY = opts.httpsProxy;
}
defaultAgents = createAgent();
defaultAgents = createAgent(opts);
}
class HttpError extends Error {

View File

@ -61,14 +61,7 @@ let defaultAgents = createAgent();
export function setGlobalProxy(opts: { httpProxy?: string; httpsProxy?: string }) {
logger.info('setGlobalProxy:', opts);
if (opts.httpProxy) {
process.env.HTTP_PROXY = opts.httpProxy;
}
if (opts.httpsProxy) {
process.env.HTTPS_PROXY = opts.httpsProxy;
}
defaultAgents = createAgent();
defaultAgents = createAgent(opts);
}
export function getGlobalAgents() {
@ -192,9 +185,13 @@ export type HttpClient = {
request<D = any, R = any>(config: HttpRequestConfig<D>): Promise<HttpClientResponse<R>>;
};
export function createAgent(opts: nodeHttp.AgentOptions = {}) {
export type CreateAgentOptions = {
httpProxy?: string;
httpsProxy?: string;
} & nodeHttp.AgentOptions;
export function createAgent(opts: CreateAgentOptions = {}) {
let httpAgent, httpsAgent;
const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy;
const httpProxy = opts.httpProxy || process.env.HTTP_PROXY || process.env.http_proxy;
if (httpProxy) {
logger.info('use httpProxy:', httpProxy);
httpAgent = new HttpProxyAgent(httpProxy, opts as any);
@ -202,7 +199,7 @@ export function createAgent(opts: nodeHttp.AgentOptions = {}) {
} else {
httpAgent = new nodeHttp.Agent(opts);
}
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
const httpsProxy = opts.httpsProxy || process.env.HTTPS_PROXY || process.env.https_proxy;
if (httpsProxy) {
logger.info('use httpsProxy:', httpsProxy);
httpsAgent = new HttpsProxyAgent(httpsProxy, opts as any);

View File

@ -57,6 +57,7 @@ defineOptions({
const formState = reactive<Partial<SysSettings>>({
public: {
registerEnabled: false,
limitUserPipelineCount: 10,
managerOtherUserPipeline: false,
icpNo: ""
},

View File

@ -2,6 +2,7 @@ import { logger } from '@certd/pipeline';
import fs from 'fs';
// @ts-ignore
import forge from 'node-forge';
import path from 'path';
export function createSelfCertificate(opts: { crtPath: string; keyPath: string }) {
// 生成密钥对
@ -32,6 +33,14 @@ export function createSelfCertificate(opts: { crtPath: string; keyPath: string }
logger.info('生成自签名证书成功');
logger.info(`自签证书保存路径: ${opts.crtPath}`);
logger.info(`自签私钥保存路径: ${opts.keyPath}`);
const crtDir = path.dirname(opts.crtPath);
if (!fs.existsSync(crtDir)) {
fs.mkdirSync(crtDir, { recursive: true });
}
const keyDir = path.dirname(opts.keyPath);
if (!fs.existsSync(keyDir)) {
fs.mkdirSync(keyDir, { recursive: true });
}
fs.writeFileSync(opts.crtPath, pemCert);
fs.writeFileSync(opts.keyPath, pemKey);