Merge remote-tracking branch 'origin/v3.4.0' into v3.4.0

# Conflicts:
#	src/common/config.ts
This commit is contained in:
linyuchen
2024-02-20 15:38:48 +08:00

View File

@@ -4,19 +4,21 @@ import {mergeNewProperties} from "./utils";
const fs = require("fs"); const fs = require("fs");
export class ConfigUtil { export class ConfigUtil {
configPath: string; private readonly configPath: string;
private config: Config | null = null;
constructor(configPath: string) { constructor(configPath: string) {
this.configPath = configPath; this.configPath = configPath;
} }
getConfig(){ getConfig(){
try { if (this.config) {
return this._getConfig() return this.config;
}catch (e) {
console.log("获取配置文件出错", e)
} }
this.config = this.reloadConfig();
return this.config;
} }
_getConfig(): Config { reloadConfig(): Config {
let ob11Default: OB11Config = { let ob11Default: OB11Config = {
httpPort: 3000, httpPort: 3000,
httpHosts: [], httpHosts: [],
@@ -55,6 +57,7 @@ export class ConfigUtil {
} }
setConfig(config: Config) { setConfig(config: Config) {
this.config = config;
fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2), "utf-8") fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2), "utf-8")
} }