@tuya-sat/micro-script 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -23,9 +23,19 @@ const mock_1 = __importDefault(require("../module/mock"));
|
|
|
23
23
|
const paths_1 = __importDefault(require("../config/paths"));
|
|
24
24
|
const oem_micro_app_id = (0, uuid_1.v4)();
|
|
25
25
|
const entry_id = (0, uuid_1.v4)();
|
|
26
|
+
function parseCookie(cookie, key) {
|
|
27
|
+
const cookies = (cookie || "").split(";");
|
|
28
|
+
for (let cookieItem of cookies) {
|
|
29
|
+
const [cookieKey, value] = cookieItem.split("=");
|
|
30
|
+
if (cookieKey.trim() === key) {
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
26
36
|
function runMain({ port, microPort, }) {
|
|
27
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
const { debuggerConfig: { target }, } = require(paths_1.default.microConfig);
|
|
38
|
+
const { debuggerConfig: { target, additionHeaders = {} }, } = require(paths_1.default.microConfig);
|
|
29
39
|
const app = (0, express_1.default)();
|
|
30
40
|
//use mock
|
|
31
41
|
(0, mock_1.default)(app);
|
|
@@ -46,6 +56,9 @@ function runMain({ port, microPort, }) {
|
|
|
46
56
|
changeOrigin: true,
|
|
47
57
|
selfHandleResponse: true,
|
|
48
58
|
onProxyReq(proxyReq, req) {
|
|
59
|
+
//强制覆盖host字段,优先级高于changeOrigin
|
|
60
|
+
const { host } = additionHeaders;
|
|
61
|
+
host && proxyReq.setHeader("host", host);
|
|
49
62
|
if (req.url === "/api/saas-info") {
|
|
50
63
|
//该死的,会有缓存
|
|
51
64
|
proxyReq.setHeader("if-none-match", "");
|
|
@@ -57,7 +70,7 @@ function runMain({ port, microPort, }) {
|
|
|
57
70
|
}
|
|
58
71
|
let response = responseBuffer;
|
|
59
72
|
try {
|
|
60
|
-
const lang = req.headers["
|
|
73
|
+
const lang = parseCookie(req.headers["cookie"], "main-i18next");
|
|
61
74
|
const data = JSON.parse(response.toString("utf8"));
|
|
62
75
|
response = JSON.stringify(processSaasInfo(data, lang, microPort));
|
|
63
76
|
}
|
|
@@ -66,6 +79,7 @@ function runMain({ port, microPort, }) {
|
|
|
66
79
|
}
|
|
67
80
|
return response;
|
|
68
81
|
})),
|
|
82
|
+
headers: additionHeaders,
|
|
69
83
|
}));
|
|
70
84
|
const { pp, resolve } = (0, promiser_1.promiser)();
|
|
71
85
|
app.listen(port, () => {
|
|
@@ -134,5 +148,5 @@ function consturctApp(manifest, oem_micro_app_id, baseUrl, lang, port) {
|
|
|
134
148
|
};
|
|
135
149
|
}
|
|
136
150
|
function pickText(texts, lang) {
|
|
137
|
-
return lang === "en
|
|
151
|
+
return lang === "en" ? texts[1] : texts[0];
|
|
138
152
|
}
|
|
@@ -31,6 +31,7 @@ function onceFactory(fn, count = 1) {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
console.log(chalk_1.default.yellow(`Tip: 目前--main命令是个体验命令,请知悉`));
|
|
34
35
|
let defaultPort = 9000;
|
|
35
36
|
//检测端口占用情况
|
|
36
37
|
const bundledServerPort = yield portfinder_1.default.getPortPromise({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-script",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"bin": "./dist/bin/cli.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"@babel/preset-react": "^7.14.5",
|
|
16
16
|
"@babel/preset-typescript": "^7.15.0",
|
|
17
17
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.1",
|
|
18
|
-
"@tuya-sat/micro-dev-loader": "1.1.
|
|
19
|
-
"@tuya-sat/micro-dev-proxy": "1.1.
|
|
20
|
-
"@tuya-sat/micro-utils": "1.1.
|
|
18
|
+
"@tuya-sat/micro-dev-loader": "1.1.1",
|
|
19
|
+
"@tuya-sat/micro-dev-proxy": "1.1.1",
|
|
20
|
+
"@tuya-sat/micro-utils": "1.1.1",
|
|
21
21
|
"babel-loader": "^8.2.2",
|
|
22
22
|
"babel-plugin-import": "^1.13.3",
|
|
23
23
|
"chalk": "4.1.2",
|