youzanyun-devtool-worker
Version:
- web - ws - proxy
42 lines (41 loc) • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const spring4js_nodejs_1 = require("spring4js-nodejs");
const axios_1 = tslib_1.__importDefault(require("axios"));
let BuiltInAppActionService = class BuiltInAppActionService {
async start() { }
async processRequest(ctx, next) {
const { request: { href }, headers, } = ctx;
if (/^https:\/\/www\.youzan\.com\/v4\/apps\/app-container/.test(href)) {
try {
const res = await axios_1.default.get(href, {
headers: Object.assign(Object.assign({}, headers), { "accept-encoding": "gzip, deflate" }),
responseType: "text",
});
ctx.status = res.status;
const scriptText = "<script>window._global.isEmbed = true;</script></head>";
const result = res.data.replace("</head>", scriptText);
ctx.set(res.headers);
ctx.body = result;
}
catch (e) {
console.log("err", e);
ctx.body = "";
}
return true;
}
if (/^https:\/\/.*\.isv\.youzan\.com/.test(href)) {
const { data: { data: { target }, }, } = await axios_1.default.get("http://127.0.0.1:31240/api/built-in-app/get-target");
if (!/^https:\/\/.*\.isv\.youzan\.com/.test(target)) {
ctx.redirect(target);
return true;
}
}
return false;
}
};
BuiltInAppActionService = tslib_1.__decorate([
spring4js_nodejs_1.Service()
], BuiltInAppActionService);
exports.default = BuiltInAppActionService;