UNPKG

env-manage-plugin

Version:

A dev env plugin that integrates an Express server with request proxying capabilities.

56 lines (55 loc) 2.66 kB
import { EnvController } from "./controllers/EnvController.js"; import { DevServerController } from "./controllers/DevServerController.js"; import { RouteRuleController } from "./controllers/RouteRuleController.js"; import { PasswordController } from "./controllers/PasswordController.js"; import { EnvRepo } from "./repositories/EnvRepo.js"; import { EnvService } from "./service/EnvService.js"; import { DevServerService } from "./service/DevServerService.js"; import { DevServerRepo } from "./repositories/DevServerRepo.js"; import { RouteRuleRepo } from "./repositories/RouteRuleRepo.js"; import { RouteRuleService } from "./service/RouteRuleService.js"; import { PasswordRepo } from "./repositories/PasswordRepo.js"; import { PasswordService } from "./service/PasswordService.js"; import { ProxyAutoStarter } from "./service/ProxyAutoStarterService.js"; class Container { constructor() { this.dependencies = new Map(); // 环境和服务的注册 const envRepo = new EnvRepo(); const devServerRepo = new DevServerRepo(); const routeRuleRepo = new RouteRuleRepo(); const passwordRepo = new PasswordRepo(); // configIns.initConfig(); this.register("envService", new EnvService(envRepo, devServerRepo, routeRuleRepo)); this.register("envController", new EnvController(this.get("envService"))); // 开发服务器服务和控制器的注册 this.register("devServerService", new DevServerService(devServerRepo, envRepo)); this.register("devServerController", new DevServerController(this.get("devServerService"))); // 路由规则服务和控制器的注册 this.register("routeRuleService", new RouteRuleService(routeRuleRepo, envRepo)); this.register("routeRuleController", new RouteRuleController(this.get("routeRuleService"))); // 密码服务和控制器的注册 this.register("passwordService", new PasswordService(passwordRepo)); this.register("passwordController", new PasswordController(this.get("passwordService"))); setTimeout(() => { new ProxyAutoStarter(envRepo, this.get("envService"), routeRuleRepo); }, 5000); } static getInstance() { if (!this.instance) { this.instance = new Container(); } return this.instance; } register(key, value) { this.dependencies.set(key, value); return this; } get(key) { if (!this.dependencies.has(key)) { throw new Error(`Dependency ${key} not found`); } return this.dependencies.get(key); } } export { Container };