@lark-apaas/devtool-kits 1.2.15-beta.0 → 1.2.16-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/devtool-kits",
3
- "version": "1.2.15-beta.0",
3
+ "version": "1.2.16-beta.0",
4
4
  "description": "FullStack Devtool Kits",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/dist/error.html DELETED
@@ -1,195 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="zh-CN">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>错误页面</title>
7
- <style>
8
- * {
9
- margin: 0;
10
- padding: 0;
11
- box-sizing: border-box;
12
- }
13
-
14
- body {
15
- font-family: "PingFang SC", -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
16
- 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
17
- sans-serif;
18
- -webkit-font-smoothing: antialiased;
19
- -moz-osx-font-smoothing: grayscale;
20
- }
21
-
22
- .overlay-container {
23
- min-height: 100vh;
24
- display: flex;
25
- align-items: center;
26
- justify-content: center;
27
- background-color: #fff;
28
- }
29
-
30
- .overlay-content {
31
- display: flex;
32
- flex-direction: column;
33
- justify-content: center;
34
- align-items: center;
35
- text-align: center;
36
- }
37
-
38
- .overlay-error-image {
39
- margin-bottom: 12px; /* mb-3 */
40
- width: 100px; /* w-[100px] */
41
- height: auto;
42
- }
43
-
44
- .overlay-title {
45
- color: #1F2329;
46
- text-align: center;
47
- font-size: 14px;
48
- font-style: normal;
49
- font-weight: 500;
50
- line-height: 22px;
51
- }
52
- </style>
53
-
54
- <script>
55
- // 全局错误对象
56
- let clientBasePath = '{{.clientBasePath}}';
57
- // 探针配置
58
- const PROBE_INTERVAL = 2000; // 探测间隔 2 秒
59
- const PROBE_TIMEOUT = 3000; // 单次请求超时 5 秒
60
- let probeTimer = null;
61
-
62
- // 初始化页面
63
- function init() {
64
- // 通知前端,渲染错误页面已准备就绪
65
- sendPostMessage({
66
- type: 'ServiceStartupFail'
67
- });
68
-
69
- // 启动服务恢复探针
70
- startServiceProbe();
71
- }
72
-
73
- // 启动服务恢复探针
74
- function startServiceProbe() {
75
- console.log('[Probe] 启动服务恢复探针,间隔:', PROBE_INTERVAL, 'ms');
76
-
77
- // 立即执行一次探测
78
- probeService();
79
-
80
- // 设置定时探测
81
- probeTimer = setInterval(probeService, PROBE_INTERVAL);
82
- }
83
-
84
- // 停止探针
85
- function stopServiceProbe() {
86
- if (probeTimer) {
87
- clearInterval(probeTimer);
88
- probeTimer = null;
89
- console.log('[Probe] 服务恢复探针已停止');
90
- }
91
- }
92
-
93
- // 探测服务是否恢复
94
- async function probeService() {
95
- try {
96
- console.log('[Probe] 探测服务状态: /dev/logs/health');
97
-
98
- // 使用 AbortController 实现超时控制
99
- const controller = new AbortController();
100
- const timeoutId = setTimeout(() => controller.abort(), PROBE_TIMEOUT);
101
-
102
- const response = await fetch(`${clientBasePath}/dev/logs/health`, {
103
- method: 'GET',
104
- cache: 'no-cache',
105
- redirect: 'manual', // 不自动跟随重定向
106
- signal: controller.signal
107
- });
108
-
109
- clearTimeout(timeoutId);
110
-
111
- console.log('[Probe] 状态码:', response.status);
112
-
113
- // 如果收到 302/303 重定向,说明代理层正在恢复中,继续探测
114
- if (response.status === 302 || response.status === 303) {
115
- console.log('[Probe] 收到重定向响应,服务可能正在恢复,继续探测');
116
- return;
117
- }
118
-
119
- // 如果是 502,说明代理遇到错误,继续探测
120
- if (response.status === 502) {
121
- console.log('[Probe] 服务未恢复(502),继续探测');
122
- return;
123
- }
124
-
125
- // 如果是 200,解析健康检查结果
126
- if (response.status === 200) {
127
- try {
128
- const data = await response.json();
129
-
130
- // 检查健康状态
131
- if (data.status === 'healthy') {
132
- console.log('[Probe] 服务已恢复,响应时间:', data.responseTime, 'ms');
133
- stopServiceProbe();
134
-
135
- // 延迟一小段时间后刷新,让日志输出完整
136
- setTimeout(() => {
137
- console.log('[Probe] 刷新页面...');
138
- const currentUrl = window.location.pathname + window.location.search;
139
- window.location.href = currentUrl;
140
- }, 300);
141
- } else {
142
- console.log('[Probe] 服务状态:', data.status, '错误:', data.error);
143
- }
144
- } catch (e) {
145
- console.log('[Probe] 解析响应失败:', e.message, '继续探测');
146
- }
147
- } else if (response.status === 503) {
148
- // 503 表示服务不健康,继续探测
149
- console.log('[Probe] 服务不健康(503),继续探测');
150
- } else {
151
- console.log('[Probe] 收到非预期状态码:', response.status, '继续探测');
152
- }
153
- } catch (error) {
154
- // 网络错误、超时或服务未恢复
155
- if (error.name === 'AbortError') {
156
- console.log('[Probe] 探测超时');
157
- } else {
158
- console.log('[Probe] 探测失败:', error.message);
159
- }
160
- // 继续下一次探测
161
- }
162
- }
163
-
164
- // 发送 postMessage
165
- function sendPostMessage(message, targetOrigin) {
166
- const origin = targetOrigin || parentOrigin || undefined;
167
- if (!origin) return;
168
- console.log('sendPostMessage', message, origin);
169
- window.parent.postMessage(message, origin);
170
- }
171
- const parentOrigin = '{{.parentOrigin}}';
172
-
173
- // 页面加载完成后初始化
174
- if (document.readyState === 'loading') {
175
- document.addEventListener('DOMContentLoaded', init);
176
- } else {
177
- init();
178
- }
179
- </script>
180
- </head>
181
- <body>
182
- <div class="overlay-container">
183
- <div class="overlay-content">
184
- <img
185
- src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylcylz_fsph_ryhs/ljhwZthlaukjlkulzlp/feisuda/template/illustration_empty_negative_error.svg"
186
- alt="Error"
187
- class="overlay-error-image"
188
- width="100"
189
- height="100"
190
- />
191
- <p class="overlay-title">服务不可用</p>
192
- </div>
193
- </div>
194
- </body>
195
- </html>