mirror of https://github.com/certd/certd
fix: 修复启动时自签证书无法保存的bug
parent
abd2dcf2e8
commit
526c48450b
|
@ -8,7 +8,7 @@ function createAgent(opts = {}) {
|
||||||
let httpAgent;
|
let httpAgent;
|
||||||
let
|
let
|
||||||
httpsAgent;
|
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) {
|
if (httpProxy) {
|
||||||
log(`acme use httpProxy:${httpProxy}`);
|
log(`acme use httpProxy:${httpProxy}`);
|
||||||
httpAgent = new HttpProxyAgent(httpProxy, opts);
|
httpAgent = new HttpProxyAgent(httpProxy, opts);
|
||||||
|
@ -16,7 +16,7 @@ function createAgent(opts = {}) {
|
||||||
else {
|
else {
|
||||||
httpAgent = new nodeHttp.Agent(opts);
|
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) {
|
if (httpsProxy) {
|
||||||
log(`acme use httpsProxy:${httpsProxy}`);
|
log(`acme use httpsProxy:${httpsProxy}`);
|
||||||
httpsAgent = new HttpsProxyAgent(httpsProxy, opts);
|
httpsAgent = new HttpsProxyAgent(httpsProxy, opts);
|
||||||
|
@ -38,14 +38,7 @@ function getGlobalAgents() {
|
||||||
|
|
||||||
function setGlobalProxy(opts) {
|
function setGlobalProxy(opts) {
|
||||||
log('acme setGlobalProxy:', opts);
|
log('acme setGlobalProxy:', opts);
|
||||||
if (opts.httpProxy) {
|
defaultAgents = createAgent(opts);
|
||||||
process.env.HTTP_PROXY = opts.httpProxy;
|
|
||||||
}
|
|
||||||
if (opts.httpsProxy) {
|
|
||||||
process.env.HTTPS_PROXY = opts.httpsProxy;
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultAgents = createAgent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class HttpError extends Error {
|
class HttpError extends Error {
|
||||||
|
|
|
@ -61,14 +61,7 @@ let defaultAgents = createAgent();
|
||||||
|
|
||||||
export function setGlobalProxy(opts: { httpProxy?: string; httpsProxy?: string }) {
|
export function setGlobalProxy(opts: { httpProxy?: string; httpsProxy?: string }) {
|
||||||
logger.info('setGlobalProxy:', opts);
|
logger.info('setGlobalProxy:', opts);
|
||||||
if (opts.httpProxy) {
|
defaultAgents = createAgent(opts);
|
||||||
process.env.HTTP_PROXY = opts.httpProxy;
|
|
||||||
}
|
|
||||||
if (opts.httpsProxy) {
|
|
||||||
process.env.HTTPS_PROXY = opts.httpsProxy;
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultAgents = createAgent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getGlobalAgents() {
|
export function getGlobalAgents() {
|
||||||
|
@ -192,9 +185,13 @@ 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: nodeHttp.AgentOptions = {}) {
|
export type CreateAgentOptions = {
|
||||||
|
httpProxy?: string;
|
||||||
|
httpsProxy?: string;
|
||||||
|
} & nodeHttp.AgentOptions;
|
||||||
|
export function createAgent(opts: CreateAgentOptions = {}) {
|
||||||
let httpAgent, httpsAgent;
|
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) {
|
if (httpProxy) {
|
||||||
logger.info('use httpProxy:', httpProxy);
|
logger.info('use httpProxy:', httpProxy);
|
||||||
httpAgent = new HttpProxyAgent(httpProxy, opts as any);
|
httpAgent = new HttpProxyAgent(httpProxy, opts as any);
|
||||||
|
@ -202,7 +199,7 @@ export function createAgent(opts: nodeHttp.AgentOptions = {}) {
|
||||||
} else {
|
} else {
|
||||||
httpAgent = new nodeHttp.Agent(opts);
|
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) {
|
if (httpsProxy) {
|
||||||
logger.info('use httpsProxy:', httpsProxy);
|
logger.info('use httpsProxy:', httpsProxy);
|
||||||
httpsAgent = new HttpsProxyAgent(httpsProxy, opts as any);
|
httpsAgent = new HttpsProxyAgent(httpsProxy, opts as any);
|
||||||
|
|
|
@ -57,6 +57,7 @@ defineOptions({
|
||||||
const formState = reactive<Partial<SysSettings>>({
|
const formState = reactive<Partial<SysSettings>>({
|
||||||
public: {
|
public: {
|
||||||
registerEnabled: false,
|
registerEnabled: false,
|
||||||
|
limitUserPipelineCount: 10,
|
||||||
managerOtherUserPipeline: false,
|
managerOtherUserPipeline: false,
|
||||||
icpNo: ""
|
icpNo: ""
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { logger } from '@certd/pipeline';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import forge from 'node-forge';
|
import forge from 'node-forge';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
export function createSelfCertificate(opts: { crtPath: string; keyPath: string }) {
|
export function createSelfCertificate(opts: { crtPath: string; keyPath: string }) {
|
||||||
// 生成密钥对
|
// 生成密钥对
|
||||||
|
@ -32,6 +33,14 @@ export function createSelfCertificate(opts: { crtPath: string; keyPath: string }
|
||||||
logger.info('生成自签名证书成功');
|
logger.info('生成自签名证书成功');
|
||||||
logger.info(`自签证书保存路径: ${opts.crtPath}`);
|
logger.info(`自签证书保存路径: ${opts.crtPath}`);
|
||||||
logger.info(`自签私钥保存路径: ${opts.keyPath}`);
|
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.crtPath, pemCert);
|
||||||
fs.writeFileSync(opts.keyPath, pemKey);
|
fs.writeFileSync(opts.keyPath, pemKey);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue