This commit is contained in:
2025-05-30 18:16:36 +08:00
parent 84d9fb2455
commit 239ba3ad10
7 changed files with 115 additions and 37 deletions

View File

@@ -62,6 +62,8 @@ export type ReturnInitConfigType = ReturnType<typeof initConfig>;
type AuthPermission = {
type?: 'auth-proxy' | 'public' | 'private' | 'project';
username?: string; // 用户名
admin?: Omit<AuthPermission, 'admin'>;
};
export type AssistantConfigData = {
pageApi?: string; // https://kevisual.cn
@@ -99,6 +101,11 @@ export type AssistantConfigData = {
[key: string]: string;
};
auth?: AuthPermission;
https?: {
type?: 'https' | 'http';
keyPath?: string; // 证书私钥路径
certPath?: string; // 证书路径
};
};
let assistantConfig: AssistantConfigData;
type AssistantConfigOptions = {

View File

@@ -21,6 +21,30 @@ export class HttpsPem {
cert: string;
constructor(assistantConfig: AssistantConfig) {
this.assistantConfig = assistantConfig;
this.#initKeyCert();
}
#initKeyCert() {
this.assistantConfig.checkMounted();
const config = this.assistantConfig.getConfig();
if (config.https) {
const httpsType = config.https?.type || 'https';
if (httpsType !== 'https') {
console.log(chalk.yellow('当前配置文件 https.type 不是 https, 不使用证书'));
return;
}
if (config.https.keyPath) {
const keyPath = config.https.keyPath;
const certPath = config.https.certPath;
if (checkFileExists(keyPath) && checkFileExists(certPath)) {
this.key = fs.readFileSync(keyPath, 'utf-8');
this.cert = fs.readFileSync(certPath, 'utf-8');
console.log(chalk.green('使用配置文件 https.keyPath 和 https.certPath 的证书'), keyPath, certPath);
return;
} else {
console.log(chalk.red('证书路径不存在,请检查配置文件 https.keyPath 和 https.certPath 是否正确'));
}
}
}
const { key, cert } = this.getCert();
this.key = key;
this.cert = cert;

View File

@@ -0,0 +1,25 @@
import pm2 from 'pm2';
import { logger } from './logger.js';
export async function reload() {
return new Promise<void>((resolve, reject) => {
pm2.connect((err) => {
if (err) {
logger.error('PM2 connection error:', err);
return reject(err);
}
pm2.reload('assistant-server', (err) => {
if (err) {
logger.error('PM2 reload error:', err);
pm2.disconnect();
return reject(err);
}
logger.info('PM2 server reloaded successfully');
pm2.disconnect();
resolve();
});
});
});
}