env-plugin 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/Container.js +18 -0
  2. package/dist/PostProxyServer.js +33 -6
  3. package/dist/client/assets/element-plus-aWS7wRSd.js.gz +0 -0
  4. package/dist/client/assets/index-CBMR4n-V.js.gz +0 -0
  5. package/dist/client/assets/index-a3AJbcK4.css.gz +0 -0
  6. package/dist/client/assets/vue-uvJWWccw.js.gz +0 -0
  7. package/dist/client/index.html +4 -4
  8. package/dist/controllers/DevServerController.js +9 -2
  9. package/dist/controllers/EnvController.js +42 -3
  10. package/dist/controllers/ImportExportController.js +43 -0
  11. package/dist/controllers/RequestLogController.js +33 -0
  12. package/dist/controllers/SystemSettingController.js +43 -0
  13. package/dist/index.js +5 -0
  14. package/dist/repositories/DevServerRepo.js +1 -3
  15. package/dist/repositories/EnvRepo.js +6 -3
  16. package/dist/repositories/PasswordRepo.js +5 -3
  17. package/dist/repositories/RouteRuleRepo.js +5 -3
  18. package/dist/repositories/SystemSettingRepo.js +42 -0
  19. package/dist/repositories/database.js +12 -0
  20. package/dist/routes/index.js +196 -28
  21. package/dist/service/EnvService.js +58 -0
  22. package/dist/service/ImportExportService.js +333 -0
  23. package/dist/service/PasswordService.js +8 -7
  24. package/dist/service/PreProxyServer.js +102 -9
  25. package/dist/service/RequestLogService.js +69 -0
  26. package/dist/service/RouteRuleService.js +14 -14
  27. package/dist/service/SystemSettingService.js +90 -0
  28. package/dist/types/index.js +3 -0
  29. package/dist/types/shared/EnvItem.js +8 -0
  30. package/dist/types/shared/ImportExport.js +55 -0
  31. package/dist/types/shared/RequestLog.js +28 -0
  32. package/dist/types/shared/SystemSetting.js +18 -0
  33. package/dist/utils/asyncHandler.js +12 -0
  34. package/dist/utils/resourceType.js +42 -0
  35. package/dist/utils/routeBuilder.js +19 -0
  36. package/package.json +16 -3
  37. package/templates/inject/envm-switcher.js +1418 -0
  38. package/dist/client/assets/element-plus-4FTV-s7u.js.gz +0 -0
  39. package/dist/client/assets/index-C2AH0x8U.css.gz +0 -0
  40. package/dist/client/assets/index-Db97pusF.js.gz +0 -0
  41. package/dist/client/assets/vue-CRjr1oeH.js.gz +0 -0
package/dist/Container.js CHANGED
@@ -10,6 +10,13 @@ import { RouteRuleRepo } from "./repositories/RouteRuleRepo.js";
10
10
  import { RouteRuleService } from "./service/RouteRuleService.js";
11
11
  import { PasswordRepo } from "./repositories/PasswordRepo.js";
12
12
  import { PasswordService } from "./service/PasswordService.js";
13
+ import { RequestLogService } from "./service/RequestLogService.js";
14
+ import { RequestLogController } from "./controllers/RequestLogController.js";
15
+ import { ImportExportService } from "./service/ImportExportService.js";
16
+ import { ImportExportController } from "./controllers/ImportExportController.js";
17
+ import { SystemSettingRepo } from "./repositories/SystemSettingRepo.js";
18
+ import { SystemSettingService } from "./service/SystemSettingService.js";
19
+ import { SystemSettingController } from "./controllers/SystemSettingController.js";
13
20
  import { ProxyAutoStarter } from "./service/ProxyAutoStarterService.js";
14
21
  class Container {
15
22
  constructor() {
@@ -31,6 +38,17 @@ class Container {
31
38
  // 密码服务和控制器的注册
32
39
  this.register("passwordService", new PasswordService(passwordRepo));
33
40
  this.register("passwordController", new PasswordController(this.get("passwordService")));
41
+ // 请求日志服务和控制器
42
+ const requestLogService = new RequestLogService();
43
+ this.register("requestLogService", requestLogService);
44
+ this.register("requestLogController", new RequestLogController(requestLogService));
45
+ // 导入导出服务和控制器
46
+ this.register("importExportService", new ImportExportService(envRepo, devServerRepo, routeRuleRepo, passwordRepo));
47
+ this.register("importExportController", new ImportExportController(this.get("importExportService")));
48
+ // 系统设置服务和控制器
49
+ const systemSettingService = new SystemSettingService(new SystemSettingRepo());
50
+ this.register("systemSettingService", systemSettingService);
51
+ this.register("systemSettingController", new SystemSettingController(systemSettingService));
34
52
  setTimeout(() => {
35
53
  new ProxyAutoStarter(envRepo, this.get("envService"), routeRuleRepo);
36
54
  }, 5000);
@@ -1,5 +1,5 @@
1
1
  import { join } from "path";
2
- import { WebSocketServer } from "ws";
2
+ import { WebSocketServer, WebSocket } from "ws";
3
3
  import express from "express";
4
4
  import expressStaticGzip from "express-static-gzip";
5
5
  import { createProxyMiddleware } from "http-proxy-middleware";
@@ -14,7 +14,8 @@ const __filename = fileURLToPath(currentModuleUrl); // 当前文件的完整路
14
14
  // 获取目录路径
15
15
  import { dirname } from "path";
16
16
  const __dirname = dirname(__filename); // 当前文件所在的目录路径
17
- import { envLogger } from "./utils/logger.js";
17
+ import { Container } from "./Container.js";
18
+ import { envLogger, proxyLogger } from "./utils/logger.js";
18
19
  /**
19
20
  * 后置代理服务器---同时也是管理页面的服务器
20
21
  */
@@ -29,7 +30,9 @@ class PostProxyServer {
29
30
  // 静态资源
30
31
  app.use(expressStaticGzip(join(__dirname, "client"), {}));
31
32
  // 注入资源
32
- app.use("/envm-inject", express.static(join(process.cwd(), this.config.injectScriptDir || ""), {}));
33
+ // 优先从用户自定义目录加载(如 .envm/),找不到时回退到内置 templates/inject/
34
+ app.use("/envm-inject", express.static(join(process.cwd(), this.config.injectScriptDir || "")));
35
+ app.use("/envm-inject", express.static(join(__dirname, "..", "templates", "inject")));
33
36
  // 统一处理响应
34
37
  app.use(responseEnhancer);
35
38
  // 初始化管理路由
@@ -49,16 +52,40 @@ class PostProxyServer {
49
52
  });
50
53
  }
51
54
  /**
52
- * 注册ws服务用于通知客户端更新
55
+ * 注册 WebSocket 服务用于通知客户端更新和推送请求日志
53
56
  * @param server
54
57
  */
55
58
  registerWs(server) {
56
- const wss = new WebSocketServer({ noServer: true });
59
+ this.wss = new WebSocketServer({ noServer: true });
57
60
  server.on("upgrade", (request, socket, head) => {
58
61
  if (request?.url?.startsWith(this.config.apiPrefix)) {
59
- wss.handleUpgrade(request, socket, head, () => { });
62
+ this.wss.handleUpgrade(request, socket, head, (ws) => {
63
+ this.wss.emit("connection", ws, request);
64
+ });
60
65
  }
61
66
  });
67
+ this.wss.on("connection", (ws) => {
68
+ proxyLogger.info("WebSocket 客户端已连接");
69
+ // 获取日志服务(Container 已由 createRouter() 初始化)
70
+ const container = Container.getInstance();
71
+ const logService = container.get("requestLogService");
72
+ // 连接时发送全量历史日志
73
+ const history = logService.getAllLogs();
74
+ ws.send(JSON.stringify({ action: "requestlog_history", data: history }));
75
+ // 订阅增量日志推送
76
+ const unsubscribe = logService.subscribe((entry) => {
77
+ if (ws.readyState === WebSocket.OPEN) {
78
+ ws.send(JSON.stringify({ action: "requestlog", data: entry }));
79
+ }
80
+ });
81
+ ws.on("close", () => {
82
+ unsubscribe();
83
+ proxyLogger.info("WebSocket 客户端已断开");
84
+ });
85
+ ws.on("error", (err) => {
86
+ proxyLogger.error(err, "WebSocket 连接错误");
87
+ });
88
+ });
62
89
  }
63
90
  /**
64
91
  * 创建后置服务器 代理转发中间件
@@ -5,10 +5,10 @@
5
5
  <link rel="icon" href="/favicon.ico" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>ENVM (环境管理)</title>
8
- <script type="module" crossorigin src="/assets/index-Db97pusF.js"></script>
9
- <link rel="modulepreload" crossorigin href="/assets/vue-CRjr1oeH.js">
10
- <link rel="modulepreload" crossorigin href="/assets/element-plus-4FTV-s7u.js">
11
- <link rel="stylesheet" crossorigin href="/assets/index-C2AH0x8U.css">
8
+ <script type="module" crossorigin src="/assets/index-CBMR4n-V.js"></script>
9
+ <link rel="modulepreload" crossorigin href="/assets/vue-uvJWWccw.js">
10
+ <link rel="modulepreload" crossorigin href="/assets/element-plus-aWS7wRSd.js">
11
+ <link rel="stylesheet" crossorigin href="/assets/index-a3AJbcK4.css">
12
12
  </head>
13
13
  <body>
14
14
  <div id="app"></div>
@@ -16,6 +16,7 @@ class DevServerController {
16
16
  res.success({ list });
17
17
  }
18
18
  catch (error) {
19
+ devServerLogger.error(error, "开发服务器列表查询请求处理失败");
19
20
  next(error);
20
21
  }
21
22
  }
@@ -35,6 +36,7 @@ class DevServerController {
35
36
  const detail = this.devServerService.findOneById(devServerData);
36
37
  if (!detail) {
37
38
  res.error("环境不存在");
39
+ return;
38
40
  }
39
41
  // 返回成功响应(包含详情数据)
40
42
  res.success({
@@ -43,6 +45,7 @@ class DevServerController {
43
45
  });
44
46
  }
45
47
  catch (error) {
48
+ devServerLogger.error(error, "开发服务器详情查询请求处理失败");
46
49
  next(error);
47
50
  }
48
51
  }
@@ -56,11 +59,12 @@ class DevServerController {
56
59
  handleCreateDevServer(req, res, next) {
57
60
  try {
58
61
  // 验证请求体
59
- const devServerItem = req.body;
62
+ const devServerItem = req.dto;
60
63
  this.devServerService.handleAddDevServer(devServerItem);
61
- res.success("开发服务器创建成功");
64
+ res.success({ message: "开发服务器创建成功" });
62
65
  }
63
66
  catch (error) {
67
+ devServerLogger.error(error, "创建开发服务器请求处理失败");
64
68
  next(error);
65
69
  }
66
70
  }
@@ -78,6 +82,7 @@ class DevServerController {
78
82
  res.success({ message: "开发服务器更新成功", server: updatedServer });
79
83
  }
80
84
  catch (error) {
85
+ devServerLogger.error(error, "更新开发服务器请求处理失败");
81
86
  next(error);
82
87
  }
83
88
  }
@@ -95,6 +100,7 @@ class DevServerController {
95
100
  res.success({ message: "开发服务器删除成功" });
96
101
  }
97
102
  catch (error) {
103
+ devServerLogger.error(error, "删除开发服务器请求处理失败");
98
104
  next(error);
99
105
  }
100
106
  }
@@ -113,6 +119,7 @@ class DevServerController {
113
119
  res.success({ message: "排序更新成功" });
114
120
  }
115
121
  catch (error) {
122
+ devServerLogger.error(error, "排序更新请求处理失败");
116
123
  next(error);
117
124
  }
118
125
  }
@@ -44,13 +44,13 @@ class EnvController {
44
44
  * @param res - Express响应对象,用于返回处理结果
45
45
  * @param next - Express下一步中间件函数,用于错误处理
46
46
  */
47
- handleDeleteEnv(req, res, next) {
47
+ async handleDeleteEnv(req, res, next) {
48
48
  try {
49
49
  // 验证请求数据
50
50
  const envData = req.dto;
51
51
  envLogger.info({ envData }, "接收删除环境请求");
52
- // 调用服务层处理业务
53
- this.envService.handleDeleteEnv(envData);
52
+ // 调用服务层处理业务(异步操作,需要 await 否则 try/catch 无法捕获错误)
53
+ await this.envService.handleDeleteEnv(envData);
54
54
  // 返回成功响应
55
55
  res.success({ message: "环境删除成功" });
56
56
  }
@@ -117,6 +117,7 @@ class EnvController {
117
117
  const detail = this.envService.findOneById(envData.id);
118
118
  if (!detail) {
119
119
  res.error("环境不存在");
120
+ return;
120
121
  }
121
122
  // 返回成功响应(包含详情数据)
122
123
  res.success({
@@ -192,5 +193,43 @@ class EnvController {
192
193
  next(error);
193
194
  }
194
195
  }
196
+ /**
197
+ * 切换代理目标(DevServer)
198
+ * @description 处理同一环境下切换 DevServer 绑定的 POST 请求,不换端口、不重启代理
199
+ * @param req - Express请求对象,包含 envId 和 devServerId(在req.dto中)
200
+ * @param res - Express响应对象,用于返回更新后的环境信息
201
+ * @param next - Express下一步中间件函数,用于错误处理
202
+ */
203
+ handleSwitchProxy(req, res, next) {
204
+ try {
205
+ const { envId, devServerId } = req.dto;
206
+ envLogger.info({ envId, devServerId }, "接收代理目标切换请求");
207
+ const updatedEnv = this.envService.handleSwitchProxy(envId, devServerId);
208
+ res.success(updatedEnv, "代理目标切换成功");
209
+ }
210
+ catch (error) {
211
+ envLogger.error(error, "代理目标切换请求处理失败");
212
+ next(error);
213
+ }
214
+ }
215
+ /**
216
+ * 切换环境
217
+ * @description 处理环境切换的POST请求(原子操作:先启动目标,再停止当前)
218
+ * @param req - Express请求对象,包含待切换的环境ID(在req.dto中)
219
+ * @param res - Express响应对象,用于返回目标环境信息
220
+ * @param next - Express下一步中间件函数,用于错误处理
221
+ */
222
+ async handleSwitchEnv(req, res, next) {
223
+ try {
224
+ const { currentEnvId, targetEnvId } = req.dto;
225
+ envLogger.info({ currentEnvId, targetEnvId }, "接收环境切换请求");
226
+ const targetEnv = await this.envService.handleSwitchEnv(currentEnvId, targetEnvId);
227
+ res.success(targetEnv, "环境切换成功");
228
+ }
229
+ catch (error) {
230
+ envLogger.error(error, "环境切换请求处理失败");
231
+ next(error);
232
+ }
233
+ }
195
234
  }
196
235
  export { EnvController };
@@ -0,0 +1,43 @@
1
+ import { envLogger } from "../utils/logger.js";
2
+ /**
3
+ * 导入/导出控制器
4
+ * 负责处理环境配置导入和导出的 HTTP 请求
5
+ */
6
+ class ImportExportController {
7
+ constructor(service) {
8
+ this.service = service;
9
+ }
10
+ /**
11
+ * 导出环境配置
12
+ * POST /dev-manage-api/env/export
13
+ */
14
+ handleExport(req, res, next) {
15
+ try {
16
+ const request = req.dto;
17
+ envLogger.info({ envIds: request.envIds }, "接收环境导出请求");
18
+ const data = this.service.exportEnvs(request);
19
+ res.success(data, "导出成功");
20
+ }
21
+ catch (error) {
22
+ envLogger.error(error, "环境导出失败");
23
+ next(error);
24
+ }
25
+ }
26
+ /**
27
+ * 导入环境配置
28
+ * POST /dev-manage-api/env/import
29
+ */
30
+ handleImport(req, res, next) {
31
+ try {
32
+ const request = req.dto;
33
+ envLogger.info("接收环境导入请求");
34
+ const result = this.service.importEnvs(request);
35
+ res.success(result, "导入完成");
36
+ }
37
+ catch (error) {
38
+ envLogger.error(error, "环境导入失败");
39
+ next(error);
40
+ }
41
+ }
42
+ }
43
+ export { ImportExportController };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * 请求日志控制器
3
+ * 提供请求日志的历史查询接口
4
+ */
5
+ class RequestLogController {
6
+ constructor(logService) {
7
+ this.logService = logService;
8
+ }
9
+ /**
10
+ * 获取请求日志列表(支持 URL 模糊匹配和状态码精确过滤)
11
+ * GET /dev-manage-api/request-log/list?url=&statusCode=
12
+ */
13
+ handleGetLogs(req, res, next) {
14
+ try {
15
+ const urlFilter = req.query.url;
16
+ const statusCodeRaw = req.query.statusCode;
17
+ const statusCodeFilter = statusCodeRaw
18
+ ? parseInt(statusCodeRaw, 10)
19
+ : undefined;
20
+ const logs = this.logService.getLogs({
21
+ url: urlFilter,
22
+ statusCode: statusCodeFilter !== undefined && !isNaN(statusCodeFilter)
23
+ ? statusCodeFilter
24
+ : undefined,
25
+ });
26
+ res.success({ list: logs, total: logs.length });
27
+ }
28
+ catch (error) {
29
+ next(error);
30
+ }
31
+ }
32
+ }
33
+ export { RequestLogController };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * 系统设置控制器
3
+ * 提供系统设置的查询与更新接口
4
+ */
5
+ class SystemSettingController {
6
+ constructor(service) {
7
+ this.service = service;
8
+ }
9
+ /**
10
+ * 获取系统设置
11
+ * GET /dev-manage-api/system-setting
12
+ */
13
+ handleGet(req, res, next) {
14
+ try {
15
+ res.success({
16
+ injectEnabled: this.service.getInjectEnabled(),
17
+ logEnabled: this.service.getLogEnabled(),
18
+ });
19
+ }
20
+ catch (error) {
21
+ next(error);
22
+ }
23
+ }
24
+ /**
25
+ * 更新系统设置
26
+ * POST /dev-manage-api/system-setting
27
+ */
28
+ handleUpdate(req, res, next) {
29
+ try {
30
+ const { injectEnabled, logEnabled } = req.dto;
31
+ this.service.setInjectEnabled(injectEnabled);
32
+ this.service.setLogEnabled(logEnabled);
33
+ res.success({
34
+ injectEnabled: this.service.getInjectEnabled(),
35
+ logEnabled: this.service.getLogEnabled(),
36
+ });
37
+ }
38
+ catch (error) {
39
+ next(error);
40
+ }
41
+ }
42
+ }
43
+ export { SystemSettingController };
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import PostProxyServer from "./PostProxyServer.js";
4
4
  import { getConfig, loadConfig } from "./utils/ResolveConfig.js";
5
5
  import { startDatabase } from "./repositories/database.js";
6
6
  import { initLoggers, logger } from "./utils/logger.js";
7
+ import { Container } from "./Container.js";
7
8
  class EnvManage {
8
9
  get config() {
9
10
  return getConfig();
@@ -27,6 +28,10 @@ class EnvManage {
27
28
  await this.checkPortAsync();
28
29
  logger.info(`端口 ${this.config.port} 可用,启动服务...`);
29
30
  await startDatabase();
31
+ // 数据库就绪后,同步系统设置(注入开关、请求日志记录开关)的持久化值到内存缓存
32
+ Container.getInstance()
33
+ .get("systemSettingService")
34
+ .init();
30
35
  new PostProxyServer();
31
36
  }
32
37
  catch (error) {
@@ -90,9 +90,7 @@ class DevServerRepo {
90
90
  throw new AppError(`更新开发服务器失败:服务器【${validationResult.data.id}】不存在`);
91
91
  }
92
92
  this.getCollection().findAndUpdate({ id: validationResult.data.id }, (server) => {
93
- if (!server) {
94
- throw new AppError(`更新开发服务器失败:服务器【${validationResult.data.id}】不存在`);
95
- }
93
+ // 此前已通过 findOneById 确认存在性,回调必定有值
96
94
  Object.assign(server, validationResult.data);
97
95
  return server;
98
96
  });
@@ -113,10 +113,13 @@ class EnvRepo {
113
113
  * @throws {Error} 当更新操作出现问题时抛出错误
114
114
  */
115
115
  update(envmItem) {
116
+ // 先检查存在性:findAndUpdate 回调仅在匹配文档时执行,
117
+ // 回调内 null 检查是死代码,必须在调用前校验
118
+ const existing = this.findOneById(envmItem.id);
119
+ if (!existing) {
120
+ throw new AppError(`未找到对应的环境【${envmItem.id}】`);
121
+ }
116
122
  this.getCollection().findAndUpdate({ id: envmItem.id }, (env) => {
117
- if (!env) {
118
- throw new AppError("未找到对应的环境");
119
- }
120
123
  Object.assign(env, envmItem);
121
124
  return env;
122
125
  });
@@ -79,10 +79,12 @@ class PasswordRepo {
79
79
  * @param passwordItem - 包含要更新的密码ID及字段的对象
80
80
  */
81
81
  update(passwordItem) {
82
+ // 先检查存在性:findAndUpdate 回调仅在匹配文档时执行
83
+ const existing = this.findOneById(passwordItem.id);
84
+ if (!existing) {
85
+ throw new Error(`未找到对应的密码【${passwordItem.id}】`);
86
+ }
82
87
  this.getCollection().findAndUpdate({ id: passwordItem.id }, (pwd) => {
83
- if (!pwd) {
84
- throw new Error("未找到对应的密码");
85
- }
86
88
  Object.assign(pwd, passwordItem);
87
89
  return pwd;
88
90
  });
@@ -81,10 +81,12 @@ class RouteRuleRepo {
81
81
  * @param routeRuleItem - 包含要更新的路由规则ID及字段的对象
82
82
  */
83
83
  update(routeRuleItem) {
84
+ // 先检查存在性:findAndUpdate 回调仅在匹配文档时执行
85
+ const existing = this.findOneById(routeRuleItem.id);
86
+ if (!existing) {
87
+ throw new Error(`未找到对应的路由规则【${routeRuleItem.id}】`);
88
+ }
84
89
  this.getCollection().findAndUpdate({ id: routeRuleItem.id }, (rule) => {
85
- if (!rule) {
86
- throw new Error("未找到对应的路由规则");
87
- }
88
90
  Object.assign(rule, routeRuleItem);
89
91
  return rule;
90
92
  });
@@ -0,0 +1,42 @@
1
+ import { getDatabase } from "./database.js";
2
+ /**
3
+ * 系统设置仓库类
4
+ * 负责全局系统设置数据的持久化操作,封装数据库交互逻辑
5
+ */
6
+ class SystemSettingRepo {
7
+ /**
8
+ * 获取系统设置数据集合
9
+ * @returns 系统设置数据集合对象
10
+ */
11
+ getCollection() {
12
+ return getDatabase().getCollection("settings");
13
+ }
14
+ /**
15
+ * 构造函数
16
+ */
17
+ constructor() { }
18
+ /**
19
+ * 获取全局设置记录
20
+ * @returns 全局设置,若未找到则返回 null
21
+ */
22
+ getGlobal() {
23
+ return this.getCollection().findOne({ id: "global" });
24
+ }
25
+ /**
26
+ * 写入或更新全局设置记录
27
+ * @param model - 要写入的完整设置信息对象
28
+ */
29
+ upsert(model) {
30
+ const existing = this.getGlobal();
31
+ if (existing) {
32
+ this.getCollection().findAndUpdate({ id: "global" }, (item) => {
33
+ Object.assign(item, model);
34
+ return item;
35
+ });
36
+ }
37
+ else {
38
+ this.getCollection().insert(model);
39
+ }
40
+ }
41
+ }
42
+ export { SystemSettingRepo };
@@ -53,6 +53,17 @@ const initPasswordsCollection = (db) => {
53
53
  });
54
54
  }
55
55
  };
56
+ /**
57
+ * 初始化系统设置集合
58
+ */
59
+ const initSettingsCollection = (db) => {
60
+ if (!db.getCollection("settings")) {
61
+ db.addCollection("settings", {
62
+ indices: ["id"],
63
+ unique: ["id"],
64
+ });
65
+ }
66
+ };
56
67
  /**
57
68
  * 手动启动数据库(核心函数)
58
69
  * @returns 数据库实例(确保单例)
@@ -77,6 +88,7 @@ export const startDatabase = () => {
77
88
  initDevServerCollection(newDb);
78
89
  initRouteRulesCollection(newDb);
79
90
  initPasswordsCollection(newDb);
91
+ initSettingsCollection(newDb);
80
92
  // 5. 赋值单例并返回
81
93
  db = newDb;
82
94
  logger.info("数据库已加载/初始化");