youzanyun-devtool-worker
Version:
- web - ws - proxy
112 lines (111 loc) • 4.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const spring4js_nodejs_1 = require("spring4js-nodejs");
const cookie = require('cookie');
const cookie2Str_1 = tslib_1.__importDefault(require("../../utils/cookie2Str"));
let ProxyService = class ProxyService {
async start() {
this.diyAppInfoCache = {};
this.lastUsedAppInfo = {};
}
async processRequest(ctx, next) {
const curContentType = ctx.headers["content-type"];
const isJsonHeader = curContentType &&
(curContentType.indexOf("json") > -1 ||
curContentType.indexOf("application/csp-report") > -1);
ctx.isJsonHeader = isJsonHeader;
const sid = await this.userService.getSid();
const diycookie = { sid };
let { projectId } = ctx.query;
let appInfo = {};
if (projectId) {
appInfo = this.diyAppInfoCache[projectId];
if (!appInfo) {
const { proName } = await this.projectService.getProjectById(projectId);
let result = await this.applicationService.getAppDetail(proName);
appInfo = result.appDetail;
this.diyAppInfoCache[projectId] = appInfo;
this.lastUsedAppInfo = appInfo;
}
}
else {
appInfo = this.lastUsedAppInfo;
}
const { appId, appName, appType } = appInfo;
diycookie['appid'] = appId;
diycookie['env'] = 'dev';
diycookie['app_env'] = 'dev';
diycookie['app_name'] = appName;
diycookie['apptype'] = appType;
let originCookies = cookie.parse(ctx.headers.cookie || "");
Object.assign(originCookies, diycookie);
ctx.headers.cookie = cookie2Str_1.default(originCookies);
let isProcessed = false;
isProcessed = await this.actionLocalFileService.processRequest(ctx, next);
if (isProcessed)
return;
isProcessed = await this.actionStatusService.processRequest(ctx, next);
if (isProcessed)
return;
isProcessed = await this.actionUploadTokenService.processRequest(ctx, next);
if (isProcessed)
return;
isProcessed = await this.actionFileRequestService.processRequest(ctx, next);
if (isProcessed)
return;
isProcessed = await this.actionToolService.processRequest(ctx, next);
if (isProcessed)
return;
isProcessed = await this.actionDesignPlatformService.processRequest(ctx, next);
if (isProcessed)
return;
isProcessed = await this.actionDataSaveService.processRequest(ctx, next);
if (isProcessed)
return;
isProcessed = await this.actionHtmlModifyService.processRequest(ctx, next);
if (isProcessed)
return;
await this.actionBypassService.processRequest(ctx, next);
}
};
tslib_1.__decorate([
spring4js_nodejs_1.Resource()
], ProxyService.prototype, "actionLocalFileService", void 0);
tslib_1.__decorate([
spring4js_nodejs_1.Resource()
], ProxyService.prototype, "actionBypassService", void 0);
tslib_1.__decorate([
spring4js_nodejs_1.Resource()
], ProxyService.prototype, "actionStatusService", void 0);
tslib_1.__decorate([
spring4js_nodejs_1.Resource()
], ProxyService.prototype, "actionUploadTokenService", void 0);
tslib_1.__decorate([
spring4js_nodejs_1.Resource()
], ProxyService.prototype, "actionToolService", void 0);
tslib_1.__decorate([
spring4js_nodejs_1.Resource()
], ProxyService.prototype, "actionFileRequestService", void 0);
tslib_1.__decorate([
spring4js_nodejs_1.Resource()
], ProxyService.prototype, "actionDesignPlatformService", void 0);
tslib_1.__decorate([
spring4js_nodejs_1.Resource()
], ProxyService.prototype, "actionDataSaveService", void 0);
tslib_1.__decorate([
spring4js_nodejs_1.Resource()
], ProxyService.prototype, "actionHtmlModifyService", void 0);
tslib_1.__decorate([
spring4js_nodejs_1.Resource()
], ProxyService.prototype, "userService", void 0);
tslib_1.__decorate([
spring4js_nodejs_1.Resource()
], ProxyService.prototype, "projectService", void 0);
tslib_1.__decorate([
spring4js_nodejs_1.Resource()
], ProxyService.prototype, "applicationService", void 0);
ProxyService = tslib_1.__decorate([
spring4js_nodejs_1.Service()
], ProxyService);
exports.default = ProxyService;