whistle.global-magic-preview-component-local-resource 1.0.4 → 1.0.6

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 CHANGED
@@ -1,24 +1,2 @@
1
- componentName: common-component-button, port: 8080, url: http://100.84.145.19:8080/common-component-button_index.js
2
- componentName: common-component-button, port: 8080, url: http://100.84.145.19:8080/common-component-button_index.js
3
-
4
- From: whistle.global-magic-preview-component-local-resource@1.0.3
5
- Node: v16.20.2
6
- Host: GL7TGHYG23
7
- Date: 12/24/2025, 3:56:02 PM
8
- TypeError: Cannot read properties of undefined (reading 'ok')
9
- at checkResPort (/Users/bytedance/Desktop/package/lib/rulesServer.js:13:15)
10
- at processTicksAndRejections (node:internal/process/task_queues:96:5)
11
- at async Server.<anonymous> (/Users/bytedance/Desktop/package/lib/rulesServer.js:36:21)componentName: common-component-button, port: 8080, url: http://100.84.145.19:8080/common-component-button_index.js
12
-
13
- From: whistle.global-magic-preview-component-local-resource@1.0.3
14
- Node: v16.20.2
15
- Host: GL7TGHYG23
16
- Date: 12/24/2025, 3:56:03 PM
17
- TypeError: Cannot read properties of undefined (reading 'ok')
18
- at checkResPort (/Users/bytedance/Desktop/package/lib/rulesServer.js:13:15)
19
- at processTicksAndRejections (node:internal/process/task_queues:96:5)
20
- at async Server.<anonymous> (/Users/bytedance/Desktop/package/lib/rulesServer.js:36:21)componentName: common-component-button, port: 8080, url: http://100.84.145.19:8080/common-component-button_index.js
21
- componentName: common-component-button, port: 8080, url: http://100.84.145.19:8080/common-component-button_index.js
22
- componentName: common-component-button, port: 8080, url: http://100.84.145.19:8080/common-component-button_index.js
23
- componentName: common-component-button, port: 8080, url: http://100.84.145.19:8080/common-component-button_index.js
24
- componentName: common-component-button, port: 8080, url: http://100.84.145.19:8080/common-component-button_index.js
1
+ componentName: tiktok-component-InfraRewardList, port: 8080, url: http://127.0.0.1:8080/tiktok-component-InfraRewardList_index.js
2
+ componentName: tiktok-component-InfraRewardList, port: 8080, url: http://127.0.0.1:8080/tiktok-component-InfraRewardList_index.js
@@ -10,27 +10,35 @@ const checkResPort = async (ports, index = 0, componentName) => {
10
10
  }
11
11
  }
12
12
  const headRes = await fetch(`${url}`, { method: "HEAD" }).catch(() => { });
13
- if (!headRes && index + 1 < ports.length) {
14
- return checkResPort(ports, index + 1, componentName)
15
- }
16
- if (headRes.ok) {
13
+ if (headRes && headRes.ok) {
17
14
  return {
18
15
  ok: headRes.ok,
19
16
  port: ports[index],
20
17
  url
21
18
  }
22
19
  }
20
+ if (index + 1 < ports.length) {
21
+ return checkResPort(ports, index + 1, componentName)
22
+ }
23
+
24
+ return {
25
+ ok: false,
26
+ port: ports[index],
27
+ url
28
+ }
29
+
23
30
  }
24
31
 
25
32
  module.exports = async (server) => {
26
33
  server.on('request', async (req, res) => {
27
34
  const { url, method } = req;
28
- const reg = /common-component-[^_]+/
35
+ const reg = /otter_(.+)-component-[^_]+/
29
36
  const [componentName] = url.match(reg) || [];
30
37
  const ports = [8080, 8082, 8084, 8086, 8088]
31
- const headRes = await checkResPort(ports, 0, componentName)
38
+ const [, name] = componentName?.split("_") || []
39
+ const headRes = await checkResPort(ports, 0, name)
32
40
  if (headRes?.ok && method === "GET") {
33
- console.log(`componentName: ${componentName}, port: ${headRes.port}, url: ${headRes.url}`)
41
+ console.log(`componentName: ${name}, port: ${headRes.port}, url: ${headRes.url}`)
34
42
  res.end(`https://sf16-website.neutral.ttwstatic.com${url} ${headRes.url}`);
35
43
  } else {
36
44
  res.end();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whistle.global-magic-preview-component-local-resource",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "将线上JS资源转发到本地IP对应的文件",
5
5
  "main": "index.js",
6
6
  "publicConfig": {
package/rules.txt CHANGED
@@ -1 +1 @@
1
- /common-component-[^_]+/ whistle.global-magic-preview-component-local-resource://
1
+ /otter_(.+)-component-[^_]+/ whistle.global-magic-preview-component-local-resource://