whistle.global-magic-preview-component-local-resource 1.0.0
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.
- package/.console.log +23 -0
- package/README.md +8 -0
- package/_rules.txt +0 -0
- package/index.js +2 -0
- package/lib/rulesServer.js +43 -0
- package/package.json +28 -0
- package/rules.txt +2 -0
- package/ui/index.html +14 -0
package/.console.log
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
From: whistle.demo-redirect@1.0.1
|
|
3
|
+
Node: v16.20.2
|
|
4
|
+
Host: GL7TGHYG23
|
|
5
|
+
Date: 12/24/2025, 12:01:36 PM
|
|
6
|
+
TypeError: Cannot read properties of undefined (reading 'ok')
|
|
7
|
+
at checkResPort (/Users/bytedance/Desktop/package/lib/rulesServer.js:9:15)
|
|
8
|
+
at processTicksAndRejections (node:internal/process/task_queues:96:5)
|
|
9
|
+
at async Server.<anonymous> (/Users/bytedance/Desktop/package/lib/rulesServer.js:28:21)新的 common-component-button
|
|
10
|
+
新的 common-component-button
|
|
11
|
+
新的 common-component-button
|
|
12
|
+
新的 common-component-image
|
|
13
|
+
新的 common-component-button
|
|
14
|
+
新的 common-component-image
|
|
15
|
+
|
|
16
|
+
From: whistle.demo-redirect@1.0.1
|
|
17
|
+
Node: v16.20.2
|
|
18
|
+
Host: GL7TGHYG23
|
|
19
|
+
Date: 12/24/2025, 2:10:36 PM
|
|
20
|
+
TypeError: Cannot read properties of undefined (reading 'ok')
|
|
21
|
+
at checkResPort (/Users/bytedance/Desktop/package/lib/rulesServer.js:13:15)
|
|
22
|
+
at processTicksAndRejections (node:internal/process/task_queues:96:5)
|
|
23
|
+
at async Server.<anonymous> (/Users/bytedance/Desktop/package/lib/rulesServer.js:33:21)
|
package/README.md
ADDED
package/_rules.txt
ADDED
|
File without changes
|
package/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const fetch = require('node-fetch');
|
|
2
|
+
|
|
3
|
+
const checkResPort = async (ports, index = 0, componentName) => {
|
|
4
|
+
const url = `http://127.0.0.1:${ports[index]}/${componentName}_index.js`
|
|
5
|
+
if (index >= ports.length) {
|
|
6
|
+
return {
|
|
7
|
+
ok: false,
|
|
8
|
+
port: ports[index],
|
|
9
|
+
url
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const headRes = await fetch(`${url}`, { method: "HEAD" }).catch(() => { });
|
|
13
|
+
if (headRes.ok) {
|
|
14
|
+
return {
|
|
15
|
+
ok: headRes.ok,
|
|
16
|
+
port: ports[index],
|
|
17
|
+
url
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (index + 1 < ports.length) {
|
|
21
|
+
return checkResPort(ports, index + 1, componentName)
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
ok: false,
|
|
25
|
+
port: ports[index],
|
|
26
|
+
url
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = async (server) => {
|
|
31
|
+
server.on('request', async (req, res) => {
|
|
32
|
+
const { url, method } = req;
|
|
33
|
+
const reg = /common-component-[^_]+/
|
|
34
|
+
const [componentName] = url.match(reg) || [];
|
|
35
|
+
const ports = [8080, 8082, 8084, 8086, 8088]
|
|
36
|
+
const headRes = await checkResPort(ports, 0, componentName)
|
|
37
|
+
if (headRes?.ok && method === "GET") {
|
|
38
|
+
res.end(`https://sf16-website.neutral.ttwstatic.com${url} ${headRes.url}`);
|
|
39
|
+
} else {
|
|
40
|
+
res.end();
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "whistle.global-magic-preview-component-local-resource",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "将线上JS资源转发到本地IP对应的文件",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"publicConfig": {
|
|
7
|
+
"registry": "http://registry.npmjs.org/"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"whistle",
|
|
11
|
+
"plugin",
|
|
12
|
+
"global-magic",
|
|
13
|
+
"tt",
|
|
14
|
+
"tt-live",
|
|
15
|
+
"preview-component-local-resource"
|
|
16
|
+
],
|
|
17
|
+
"author": "suyuefeng",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"whistleConfig": {
|
|
20
|
+
"name": "preview-component-local-resource",
|
|
21
|
+
"ui": "ui/index.html",
|
|
22
|
+
"rules": "rules.txt",
|
|
23
|
+
"_rules": "_rules.txt"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"node-fetch": "^2.6.13"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/rules.txt
ADDED
package/ui/index.html
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>preview-local-resource</title>
|
|
8
|
+
</head>
|
|
9
|
+
|
|
10
|
+
<body>
|
|
11
|
+
<h1>preview-local-resource</h1>
|
|
12
|
+
</body>
|
|
13
|
+
|
|
14
|
+
</html>
|