UNPKG

zan-proxy

Version:
116 lines 3.65 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const events_1 = __importDefault(require("events")); const ip_1 = __importDefault(require("ip")); const lodash_1 = require("lodash"); const path_1 = __importDefault(require("path")); const os_1 = __importDefault(require("os")); const typedi_1 = require("typedi"); let AppInfoService = class AppInfoService extends events_1.default { constructor(single = true) { super(); // 用户home目录 const userHome = os_1.default.homedir(); // proxy data存放目录 this.proxyDataDir = path_1.default.join(userHome, '.front-end-proxy'); // app信息 this.appInfo = { pcIp: ip_1.default.address(), proxyPort: 8001, realUiPort: 40001, single, }; this.appDir = path_1.default.join(__dirname, '../../../'); } getAppDir() { return this.appDir; } /** * 设置app 运行信息 * @param info */ setAppInfo(info) { lodash_1.assign(this.appInfo, info); this.emit('data-change', this.appInfo); } /** * 是否是单用户模式 * @returns {boolean|*} */ isSingle() { return this.appInfo.single; } /** * 本地存放数据的目录 * @returns {*} */ getProxyDataDir() { return this.proxyDataDir; } /** * 真实的 ui 端口 * @returns {string} */ getRealUiPort() { return this.appInfo.realUiPort; } /** * 设置真实的 ui 端口 * @param uiport */ setRealUiPort(uiport) { this.setAppInfo({ realUiPort: uiport, }); } /** * 真实的代理端口 * @returns {string} */ getHttpProxyPort() { return this.appInfo.proxyPort; } /** * 设置正在运行的代理端口 * @param proxyport */ setHttpProxyPort(httpProxyPort) { this.setAppInfo({ proxyPort: httpProxyPort, }); } /** * 获取机器ip * @returns {string} */ getPcIp() { return this.appInfo.pcIp; } // 是否是webui请求 isWebUiRequest(hostname, port) { return ((hostname === '127.0.0.1' || hostname === this.appInfo.pcIp) && port === this.appInfo.realUiPort); } printRuntimeInfo() { console.log(`Proxy Port: ${this.appInfo.proxyPort}`); console.log(`Manager: http://${this.appInfo.pcIp}:${this.appInfo.realUiPort}`); } }; AppInfoService = __decorate([ typedi_1.Service(), __metadata("design:paramtypes", [Object]) ], AppInfoService); exports.AppInfoService = AppInfoService; //# sourceMappingURL=appInfo.js.map