youzanyun-devtool-worker
Version:
- web - ws - proxy
37 lines (36 loc) • 1.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const path_1 = tslib_1.__importDefault(require("path"));
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
const koa_1 = tslib_1.__importDefault(require("koa"));
const koa_bodyparser_1 = tslib_1.__importDefault(require("koa-bodyparser"));
const HttpServer_1 = tslib_1.__importDefault(require("./HttpServer"));
const HttpsServer_1 = tslib_1.__importDefault(require("./HttpsServer"));
class Proxy {
constructor({ container }) {
this.container = container;
}
async start() {
let proxyService = await this.container.getServiceInstance('proxyService');
let configService = await this.container.getServiceInstance('configService');
let httpPort = configService.getProxyHttpPort();
let httpsPort = configService.getProxyHttpsPort();
let workerDir = configService.getWorkerDir();
let key = await fs_extra_1.default.readFile(path_1.default.join(workerDir, 'certificate/zproxy.key.pem'), 'utf8');
let cert = await fs_extra_1.default.readFile(path_1.default.join(workerDir, 'certificate/zproxy.crt.pem'), 'utf8');
let httpServer = new HttpServer_1.default({ httpPort, httpsPort });
let httpsServer = new HttpsServer_1.default({ httpsPort, key, cert });
let app = new koa_1.default();
app.use(koa_bodyparser_1.default({
enableTypes: ['json']
}));
app.use(async (ctx, next) => {
await proxyService.processRequest(ctx, next);
});
let callback = app.callback();
httpServer.start(callback);
httpsServer.start(callback);
}
}
exports.default = Proxy;