@lark-apaas/devtool-kits 1.0.5-alpha.2 → 1.0.5-alpha.4
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/dist/error.html +44 -16
- package/dist/index.cjs +172 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -1
- package/dist/index.d.ts +34 -1
- package/dist/index.js +171 -59
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/error.html
CHANGED
|
@@ -108,6 +108,7 @@
|
|
|
108
108
|
|
|
109
109
|
<script>
|
|
110
110
|
// 全局错误对象
|
|
111
|
+
let clientBasePath = '{{.clientBasePath}}';
|
|
111
112
|
let errorData = {
|
|
112
113
|
message: `{{.errorData.message}}`,
|
|
113
114
|
};
|
|
@@ -159,35 +160,62 @@
|
|
|
159
160
|
// 探测服务是否恢复
|
|
160
161
|
async function probeService() {
|
|
161
162
|
try {
|
|
162
|
-
|
|
163
|
-
const currentUrl = window.location.pathname + window.location.search;
|
|
164
|
-
|
|
165
|
-
console.log('[Probe] 探测服务状态:', currentUrl);
|
|
163
|
+
console.log('[Probe] 探测服务状态: /dev/health');
|
|
166
164
|
|
|
167
165
|
// 使用 AbortController 实现超时控制
|
|
168
166
|
const controller = new AbortController();
|
|
169
167
|
const timeoutId = setTimeout(() => controller.abort(), PROBE_TIMEOUT);
|
|
170
168
|
|
|
171
|
-
const response = await fetch(
|
|
172
|
-
method: '
|
|
169
|
+
const response = await fetch(`${clientBasePath}/dev/health`, {
|
|
170
|
+
method: 'GET',
|
|
173
171
|
cache: 'no-cache',
|
|
172
|
+
redirect: 'manual', // 不自动跟随重定向
|
|
174
173
|
signal: controller.signal
|
|
175
174
|
});
|
|
176
175
|
|
|
177
176
|
clearTimeout(timeoutId);
|
|
178
177
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
178
|
+
console.log('[Probe] 状态码:', response.status);
|
|
179
|
+
|
|
180
|
+
// 如果收到 302/303 重定向,说明代理层正在恢复中,继续探测
|
|
181
|
+
if (response.status === 302 || response.status === 303) {
|
|
182
|
+
console.log('[Probe] 收到重定向响应,服务可能正在恢复,继续探测');
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// 如果是 502,说明代理遇到错误,继续探测
|
|
187
|
+
if (response.status === 502) {
|
|
188
|
+
console.log('[Probe] 服务未恢复(502),继续探测');
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
183
191
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
192
|
+
// 如果是 200,解析健康检查结果
|
|
193
|
+
if (response.status === 200) {
|
|
194
|
+
try {
|
|
195
|
+
const data = await response.json();
|
|
196
|
+
|
|
197
|
+
// 检查健康状态
|
|
198
|
+
if (data.status === 'healthy') {
|
|
199
|
+
console.log('[Probe] 服务已恢复,响应时间:', data.responseTime, 'ms');
|
|
200
|
+
stopServiceProbe();
|
|
201
|
+
|
|
202
|
+
// 延迟一小段时间后刷新,让日志输出完整
|
|
203
|
+
setTimeout(() => {
|
|
204
|
+
console.log('[Probe] 刷新页面...');
|
|
205
|
+
const currentUrl = window.location.pathname + window.location.search;
|
|
206
|
+
window.location.href = currentUrl;
|
|
207
|
+
}, 300);
|
|
208
|
+
} else {
|
|
209
|
+
console.log('[Probe] 服务状态:', data.status, '错误:', data.error);
|
|
210
|
+
}
|
|
211
|
+
} catch (e) {
|
|
212
|
+
console.log('[Probe] 解析响应失败:', e.message, '继续探测');
|
|
213
|
+
}
|
|
214
|
+
} else if (response.status === 503) {
|
|
215
|
+
// 503 表示服务不健康,继续探测
|
|
216
|
+
console.log('[Probe] 服务不健康(503),继续探测');
|
|
189
217
|
} else {
|
|
190
|
-
console.log('[Probe]
|
|
218
|
+
console.log('[Probe] 收到非预期状态码:', response.status, '继续探测');
|
|
191
219
|
}
|
|
192
220
|
} catch (error) {
|
|
193
221
|
// 网络错误、超时或服务未恢复
|
package/dist/index.cjs
CHANGED
|
@@ -22320,10 +22320,10 @@ var require_layer = __commonJS({
|
|
|
22320
22320
|
var require_methods = __commonJS({
|
|
22321
22321
|
"../../../node_modules/methods/index.js"(exports2, module2) {
|
|
22322
22322
|
"use strict";
|
|
22323
|
-
var
|
|
22323
|
+
var http3 = require("http");
|
|
22324
22324
|
module2.exports = getCurrentNodeMethods() || getBasicNodeMethods();
|
|
22325
22325
|
function getCurrentNodeMethods() {
|
|
22326
|
-
return
|
|
22326
|
+
return http3.METHODS && http3.METHODS.map(/* @__PURE__ */ __name(function lowerCaseMethod(method) {
|
|
22327
22327
|
return method.toLowerCase();
|
|
22328
22328
|
}, "lowerCaseMethod"));
|
|
22329
22329
|
}
|
|
@@ -25995,13 +25995,13 @@ var require_application = __commonJS({
|
|
|
25995
25995
|
"../../../node_modules/express/lib/application.js"(exports2, module2) {
|
|
25996
25996
|
"use strict";
|
|
25997
25997
|
var finalhandler = require_finalhandler();
|
|
25998
|
-
var
|
|
25998
|
+
var Router2 = require_router();
|
|
25999
25999
|
var methods = require_methods();
|
|
26000
26000
|
var middleware = require_init();
|
|
26001
26001
|
var query = require_query();
|
|
26002
26002
|
var debug = require_src3()("express:application");
|
|
26003
26003
|
var View = require_view();
|
|
26004
|
-
var
|
|
26004
|
+
var http3 = require("http");
|
|
26005
26005
|
var compileETag = require_utils2().compileETag;
|
|
26006
26006
|
var compileQueryParser = require_utils2().compileQueryParser;
|
|
26007
26007
|
var compileTrust = require_utils2().compileTrust;
|
|
@@ -26060,7 +26060,7 @@ var require_application = __commonJS({
|
|
|
26060
26060
|
}, "defaultConfiguration");
|
|
26061
26061
|
app.lazyrouter = /* @__PURE__ */ __name(function lazyrouter() {
|
|
26062
26062
|
if (!this._router) {
|
|
26063
|
-
this._router = new
|
|
26063
|
+
this._router = new Router2({
|
|
26064
26064
|
caseSensitive: this.enabled("case sensitive routing"),
|
|
26065
26065
|
strict: this.enabled("strict routing")
|
|
26066
26066
|
});
|
|
@@ -26250,7 +26250,7 @@ var require_application = __commonJS({
|
|
|
26250
26250
|
tryRender(view, renderOptions, done);
|
|
26251
26251
|
}, "render");
|
|
26252
26252
|
app.listen = /* @__PURE__ */ __name(function listen() {
|
|
26253
|
-
var server =
|
|
26253
|
+
var server = http3.createServer(this);
|
|
26254
26254
|
return server.listen.apply(server, arguments);
|
|
26255
26255
|
}, "listen");
|
|
26256
26256
|
function logerror(err) {
|
|
@@ -26913,12 +26913,12 @@ var require_request = __commonJS({
|
|
|
26913
26913
|
var deprecate = require_depd()("express");
|
|
26914
26914
|
var isIP = require("net").isIP;
|
|
26915
26915
|
var typeis = require_type_is();
|
|
26916
|
-
var
|
|
26916
|
+
var http3 = require("http");
|
|
26917
26917
|
var fresh = require_fresh();
|
|
26918
26918
|
var parseRange = require_range_parser();
|
|
26919
26919
|
var parse = require_parseurl();
|
|
26920
26920
|
var proxyaddr = require_proxy_addr();
|
|
26921
|
-
var req = Object.create(
|
|
26921
|
+
var req = Object.create(http3.IncomingMessage.prototype);
|
|
26922
26922
|
module2.exports = req;
|
|
26923
26923
|
req.get = req.header = /* @__PURE__ */ __name(function header(name) {
|
|
26924
26924
|
if (!name) {
|
|
@@ -27344,7 +27344,7 @@ var require_response = __commonJS({
|
|
|
27344
27344
|
var deprecate = require_depd()("express");
|
|
27345
27345
|
var encodeUrl = require_encodeurl();
|
|
27346
27346
|
var escapeHtml = require_escape_html();
|
|
27347
|
-
var
|
|
27347
|
+
var http3 = require("http");
|
|
27348
27348
|
var isAbsolute3 = require_utils2().isAbsolute;
|
|
27349
27349
|
var onFinished = require_on_finished();
|
|
27350
27350
|
var path6 = require("path");
|
|
@@ -27360,7 +27360,7 @@ var require_response = __commonJS({
|
|
|
27360
27360
|
var mime = send.mime;
|
|
27361
27361
|
var resolve = path6.resolve;
|
|
27362
27362
|
var vary = require_vary();
|
|
27363
|
-
var res = Object.create(
|
|
27363
|
+
var res = Object.create(http3.ServerResponse.prototype);
|
|
27364
27364
|
module2.exports = res;
|
|
27365
27365
|
var charsetRegExp = /;\s*charset\s*=/;
|
|
27366
27366
|
res.status = /* @__PURE__ */ __name(function status(code) {
|
|
@@ -28009,7 +28009,7 @@ var require_express = __commonJS({
|
|
|
28009
28009
|
var mixin = require_merge_descriptors();
|
|
28010
28010
|
var proto = require_application();
|
|
28011
28011
|
var Route = require_route();
|
|
28012
|
-
var
|
|
28012
|
+
var Router2 = require_router();
|
|
28013
28013
|
var req = require_request();
|
|
28014
28014
|
var res = require_response();
|
|
28015
28015
|
exports2 = module2.exports = createApplication;
|
|
@@ -28043,7 +28043,7 @@ var require_express = __commonJS({
|
|
|
28043
28043
|
exports2.request = req;
|
|
28044
28044
|
exports2.response = res;
|
|
28045
28045
|
exports2.Route = Route;
|
|
28046
|
-
exports2.Router =
|
|
28046
|
+
exports2.Router = Router2;
|
|
28047
28047
|
exports2.json = bodyParser.json;
|
|
28048
28048
|
exports2.query = require_query();
|
|
28049
28049
|
exports2.raw = bodyParser.raw;
|
|
@@ -28093,6 +28093,7 @@ var index_exports = {};
|
|
|
28093
28093
|
__export(index_exports, {
|
|
28094
28094
|
createCollectLogsMiddleware: () => createCollectLogsMiddleware,
|
|
28095
28095
|
createDevLogsMiddleware: () => createDevLogsMiddleware,
|
|
28096
|
+
createHealthCheckMiddleware: () => createHealthCheckMiddleware,
|
|
28096
28097
|
createOpenapiMiddleware: () => createOpenapiMiddleware,
|
|
28097
28098
|
handleDevProxyError: () => handleDevProxyError,
|
|
28098
28099
|
normalizeBasePath: () => normalizeBasePath,
|
|
@@ -28407,7 +28408,8 @@ var import_node_fs2 = __toESM(require("fs"), 1);
|
|
|
28407
28408
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
28408
28409
|
var import_node_fs3 = require("fs");
|
|
28409
28410
|
var import_node_readline = require("readline");
|
|
28410
|
-
var
|
|
28411
|
+
var import_node_http = __toESM(require("http"), 1);
|
|
28412
|
+
var import_node_https = __toESM(require("https"), 1);
|
|
28411
28413
|
var errorHtmlTemplate = null;
|
|
28412
28414
|
function isConnectionError(err) {
|
|
28413
28415
|
const code = err.code;
|
|
@@ -28421,30 +28423,40 @@ function isConnectionError(err) {
|
|
|
28421
28423
|
return connectionErrorCodes.includes(code || "");
|
|
28422
28424
|
}
|
|
28423
28425
|
__name(isConnectionError, "isConnectionError");
|
|
28424
|
-
function checkServiceAvailable(
|
|
28426
|
+
function checkServiceAvailable(targetUrl, timeout = 1e3) {
|
|
28425
28427
|
return new Promise((resolve) => {
|
|
28426
|
-
|
|
28427
|
-
|
|
28428
|
-
|
|
28429
|
-
|
|
28430
|
-
|
|
28431
|
-
|
|
28432
|
-
|
|
28433
|
-
|
|
28434
|
-
|
|
28435
|
-
|
|
28436
|
-
|
|
28437
|
-
|
|
28438
|
-
|
|
28428
|
+
try {
|
|
28429
|
+
const url = new URL(targetUrl);
|
|
28430
|
+
const isHttps = url.protocol === "https:";
|
|
28431
|
+
const httpModule = isHttps ? import_node_https.default : import_node_http.default;
|
|
28432
|
+
const req = httpModule.request({
|
|
28433
|
+
hostname: url.hostname,
|
|
28434
|
+
port: url.port || (isHttps ? 443 : 80),
|
|
28435
|
+
path: "/",
|
|
28436
|
+
method: "HEAD",
|
|
28437
|
+
timeout
|
|
28438
|
+
}, (res) => {
|
|
28439
|
+
const available = res.statusCode !== 502 && !res.headers["x-proxy-error-page"];
|
|
28440
|
+
resolve(available);
|
|
28441
|
+
});
|
|
28442
|
+
req.on("timeout", () => {
|
|
28443
|
+
req.destroy();
|
|
28444
|
+
resolve(false);
|
|
28445
|
+
});
|
|
28446
|
+
req.on("error", () => {
|
|
28447
|
+
resolve(false);
|
|
28448
|
+
});
|
|
28449
|
+
req.end();
|
|
28450
|
+
} catch (e) {
|
|
28439
28451
|
resolve(false);
|
|
28440
|
-
}
|
|
28452
|
+
}
|
|
28441
28453
|
});
|
|
28442
28454
|
}
|
|
28443
28455
|
__name(checkServiceAvailable, "checkServiceAvailable");
|
|
28444
|
-
async function waitForServiceRecovery(
|
|
28456
|
+
async function waitForServiceRecovery(targetUrl, timeout, interval) {
|
|
28445
28457
|
const startTime = Date.now();
|
|
28446
28458
|
while (Date.now() - startTime < timeout) {
|
|
28447
|
-
const isAvailable = await checkServiceAvailable(
|
|
28459
|
+
const isAvailable = await checkServiceAvailable(targetUrl, 2e3);
|
|
28448
28460
|
if (isAvailable) {
|
|
28449
28461
|
return true;
|
|
28450
28462
|
}
|
|
@@ -28535,7 +28547,7 @@ async function readRecentErrorLogs(logDir, maxLogs, fileName) {
|
|
|
28535
28547
|
};
|
|
28536
28548
|
}
|
|
28537
28549
|
__name(readRecentErrorLogs, "readRecentErrorLogs");
|
|
28538
|
-
function injectErrorData(template, errorLogs) {
|
|
28550
|
+
function injectErrorData(template, errorLogs, clientBasePath) {
|
|
28539
28551
|
let logsText = "";
|
|
28540
28552
|
if (errorLogs.length > 0) {
|
|
28541
28553
|
logsText = errorLogs.join("\n");
|
|
@@ -28543,11 +28555,12 @@ function injectErrorData(template, errorLogs) {
|
|
|
28543
28555
|
logsText = "\u672A\u627E\u5230\u76F8\u5173\u9519\u8BEF\u65E5\u5FD7";
|
|
28544
28556
|
}
|
|
28545
28557
|
return template.replace("{{.errorData.message}}", `\u670D\u52A1\u542F\u52A8\u5F02\u5E38\uFF0C\u8BF7\u6839\u636E\u65E5\u5FD7\u4FEE\u590D\u76F8\u5173\u95EE\u9898
|
|
28546
|
-
${JSON.stringify(logsText)}`);
|
|
28558
|
+
${JSON.stringify(logsText)}`).replace("{{.clientBasePath}}", clientBasePath);
|
|
28547
28559
|
}
|
|
28548
28560
|
__name(injectErrorData, "injectErrorData");
|
|
28549
28561
|
function handleDevProxyError(err, req, res, options) {
|
|
28550
|
-
const { logDir = import_node_path2.default.join(process.cwd(), "logs"), maxErrorLogs = 100, logFileName = "server.log", retryTimeout = 5e3, retryInterval = 500, target } = options || {};
|
|
28562
|
+
const { logDir = import_node_path2.default.join(process.cwd(), "logs"), maxErrorLogs = 100, logFileName = "server.log", retryTimeout = 5e3, retryInterval = 500, target, clientBasePath = process.env.CLIENT_BASE_PATH || "/" } = options || {};
|
|
28563
|
+
const clientBasePathWithoutSlash = normalizeBasePath(clientBasePath);
|
|
28551
28564
|
console.error("[Proxy Error]:", err.message);
|
|
28552
28565
|
if (res.headersSent) {
|
|
28553
28566
|
console.error("[Proxy Error]: Headers already sent, cannot send error page");
|
|
@@ -28559,32 +28572,32 @@ function handleDevProxyError(err, req, res, options) {
|
|
|
28559
28572
|
const { logs: errorLogs, hasCompileError } = await readRecentErrorLogs(logDir, maxErrorLogs, logFileName);
|
|
28560
28573
|
if (isConnError && !hasCompileError && target) {
|
|
28561
28574
|
console.log("[Proxy Error]: Connection error without compile errors, possibly server restarting...");
|
|
28562
|
-
let targetUrl = null;
|
|
28563
28575
|
try {
|
|
28564
|
-
|
|
28576
|
+
new URL(target);
|
|
28565
28577
|
} catch (e) {
|
|
28566
28578
|
console.error("[Proxy Error]: Invalid target URL:", target);
|
|
28579
|
+
console.log("[Proxy Error]: Showing error page due to invalid target");
|
|
28567
28580
|
}
|
|
28568
|
-
|
|
28569
|
-
|
|
28570
|
-
|
|
28571
|
-
console.log(
|
|
28572
|
-
|
|
28573
|
-
|
|
28574
|
-
console.log("[Proxy Error]: Service recovered, sending redirect");
|
|
28575
|
-
sendSimpleRedirect(req, res);
|
|
28576
|
-
return;
|
|
28577
|
-
}
|
|
28578
|
-
console.log("[Proxy Error]: Service did not recover within timeout, showing error page");
|
|
28581
|
+
console.log(`[Proxy Error]: Waiting for service recovery at ${target} (timeout: ${retryTimeout}ms)...`);
|
|
28582
|
+
const recovered = await waitForServiceRecovery(target, retryTimeout, retryInterval);
|
|
28583
|
+
if (recovered) {
|
|
28584
|
+
console.log("[Proxy Error]: Service recovered within timeout, sending 302 redirect");
|
|
28585
|
+
sendSimpleRedirect(req, res);
|
|
28586
|
+
return;
|
|
28579
28587
|
}
|
|
28580
|
-
console.log("[Proxy Error]:
|
|
28588
|
+
console.log("[Proxy Error]: Service did not recover within timeout, showing error page with probe");
|
|
28589
|
+
}
|
|
28590
|
+
if (isConnError && !hasCompileError) {
|
|
28591
|
+
console.log("[Proxy Error]: Showing error page with auto-refresh probe");
|
|
28592
|
+
} else {
|
|
28593
|
+
console.log("[Proxy Error]: Compile error or non-connection error, showing error page");
|
|
28581
28594
|
}
|
|
28582
|
-
console.log("[Proxy Error]: Compile error or non-connection error, showing error page");
|
|
28583
28595
|
const template = getErrorHtmlTemplate();
|
|
28584
|
-
const html = injectErrorData(template, errorLogs);
|
|
28596
|
+
const html = injectErrorData(template, errorLogs, clientBasePathWithoutSlash);
|
|
28585
28597
|
res.writeHead(502, {
|
|
28586
28598
|
"Content-Type": "text/html; charset=utf-8",
|
|
28587
|
-
"Cache-Control": "no-cache, no-store, must-revalidate"
|
|
28599
|
+
"Cache-Control": "no-cache, no-store, must-revalidate",
|
|
28600
|
+
"X-Proxy-Error-Page": "true"
|
|
28588
28601
|
});
|
|
28589
28602
|
res.end(html);
|
|
28590
28603
|
} catch (error) {
|
|
@@ -28614,8 +28627,99 @@ __name(sendSimpleRedirect, "sendSimpleRedirect");
|
|
|
28614
28627
|
// src/middlewares/index.ts
|
|
28615
28628
|
var import_node_path8 = __toESM(require("path"), 1);
|
|
28616
28629
|
|
|
28617
|
-
// src/middlewares/
|
|
28630
|
+
// src/middlewares/health-check/router.ts
|
|
28618
28631
|
var import_express = __toESM(require_express2(), 1);
|
|
28632
|
+
var import_node_http2 = __toESM(require("http"), 1);
|
|
28633
|
+
function checkServiceHealth(host, port, timeout) {
|
|
28634
|
+
return new Promise((resolve) => {
|
|
28635
|
+
const startTime = Date.now();
|
|
28636
|
+
const req = import_node_http2.default.request({
|
|
28637
|
+
hostname: host,
|
|
28638
|
+
port,
|
|
28639
|
+
path: "/",
|
|
28640
|
+
method: "HEAD",
|
|
28641
|
+
timeout
|
|
28642
|
+
}, (_res) => {
|
|
28643
|
+
const responseTime = Date.now() - startTime;
|
|
28644
|
+
resolve({
|
|
28645
|
+
available: true,
|
|
28646
|
+
responseTime
|
|
28647
|
+
});
|
|
28648
|
+
});
|
|
28649
|
+
req.on("timeout", () => {
|
|
28650
|
+
req.destroy();
|
|
28651
|
+
resolve({
|
|
28652
|
+
available: false,
|
|
28653
|
+
error: "Request timeout"
|
|
28654
|
+
});
|
|
28655
|
+
});
|
|
28656
|
+
req.on("error", (err) => {
|
|
28657
|
+
resolve({
|
|
28658
|
+
available: false,
|
|
28659
|
+
error: err.message
|
|
28660
|
+
});
|
|
28661
|
+
});
|
|
28662
|
+
req.end();
|
|
28663
|
+
});
|
|
28664
|
+
}
|
|
28665
|
+
__name(checkServiceHealth, "checkServiceHealth");
|
|
28666
|
+
function createHealthCheckRouter(options = {}) {
|
|
28667
|
+
const { targetPort = Number(process.env.SERVER_PORT) || 3e3, targetHost = "localhost", timeout = 2e3 } = options;
|
|
28668
|
+
const router = (0, import_express.Router)();
|
|
28669
|
+
router.get("/", async (_req, res) => {
|
|
28670
|
+
try {
|
|
28671
|
+
const result = await checkServiceHealth(targetHost, targetPort, timeout);
|
|
28672
|
+
if (result.available) {
|
|
28673
|
+
res.status(200).json({
|
|
28674
|
+
status: "healthy",
|
|
28675
|
+
service: `${targetHost}:${targetPort}`,
|
|
28676
|
+
responseTime: result.responseTime,
|
|
28677
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
28678
|
+
});
|
|
28679
|
+
} else {
|
|
28680
|
+
res.status(503).json({
|
|
28681
|
+
status: "unhealthy",
|
|
28682
|
+
service: `${targetHost}:${targetPort}`,
|
|
28683
|
+
error: result.error,
|
|
28684
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
28685
|
+
});
|
|
28686
|
+
}
|
|
28687
|
+
} catch (error) {
|
|
28688
|
+
res.status(500).json({
|
|
28689
|
+
status: "error",
|
|
28690
|
+
service: `${targetHost}:${targetPort}`,
|
|
28691
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
28692
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
28693
|
+
});
|
|
28694
|
+
}
|
|
28695
|
+
});
|
|
28696
|
+
return router;
|
|
28697
|
+
}
|
|
28698
|
+
__name(createHealthCheckRouter, "createHealthCheckRouter");
|
|
28699
|
+
|
|
28700
|
+
// src/middlewares/health-check/index.ts
|
|
28701
|
+
var HEALTH_CHECK_ROUTES = [
|
|
28702
|
+
{
|
|
28703
|
+
method: "GET",
|
|
28704
|
+
path: "/",
|
|
28705
|
+
description: "Check if target service is healthy and available"
|
|
28706
|
+
}
|
|
28707
|
+
];
|
|
28708
|
+
function createHealthCheckMiddleware(options = {}) {
|
|
28709
|
+
return {
|
|
28710
|
+
name: "health-check",
|
|
28711
|
+
mountPath: "/dev/health",
|
|
28712
|
+
routes: HEALTH_CHECK_ROUTES,
|
|
28713
|
+
enabled: /* @__PURE__ */ __name((context) => context.isDev, "enabled"),
|
|
28714
|
+
createRouter: /* @__PURE__ */ __name((_context) => {
|
|
28715
|
+
return createHealthCheckRouter(options);
|
|
28716
|
+
}, "createRouter")
|
|
28717
|
+
};
|
|
28718
|
+
}
|
|
28719
|
+
__name(createHealthCheckMiddleware, "createHealthCheckMiddleware");
|
|
28720
|
+
|
|
28721
|
+
// src/middlewares/openapi/router.ts
|
|
28722
|
+
var import_express2 = __toESM(require_express2(), 1);
|
|
28619
28723
|
|
|
28620
28724
|
// src/middlewares/openapi/controller.ts
|
|
28621
28725
|
var import_promises = __toESM(require("fs/promises"), 1);
|
|
@@ -28862,7 +28966,7 @@ __name(createOpenapiHandler, "createOpenapiHandler");
|
|
|
28862
28966
|
// src/middlewares/openapi/router.ts
|
|
28863
28967
|
function createOpenapiRouter(options, context) {
|
|
28864
28968
|
const { openapiFilePath, enableEnhancement, serverDir } = options;
|
|
28865
|
-
const router =
|
|
28969
|
+
const router = import_express2.default.Router();
|
|
28866
28970
|
const handler = createOpenapiHandler(openapiFilePath, enableEnhancement, serverDir);
|
|
28867
28971
|
router.get("/openapi.json", (req, res) => handler(req, res, context));
|
|
28868
28972
|
return router;
|
|
@@ -28896,7 +29000,7 @@ function createOpenapiMiddleware(options) {
|
|
|
28896
29000
|
__name(createOpenapiMiddleware, "createOpenapiMiddleware");
|
|
28897
29001
|
|
|
28898
29002
|
// src/middlewares/dev-logs/router.ts
|
|
28899
|
-
var
|
|
29003
|
+
var import_express3 = __toESM(require_express2(), 1);
|
|
28900
29004
|
|
|
28901
29005
|
// src/middlewares/dev-logs/utils.ts
|
|
28902
29006
|
var import_node_fs6 = require("fs");
|
|
@@ -29341,7 +29445,7 @@ __name(createGetLogFileHandler, "createGetLogFileHandler");
|
|
|
29341
29445
|
// src/middlewares/dev-logs/router.ts
|
|
29342
29446
|
function createDevLogRouter(options = {}) {
|
|
29343
29447
|
const logDir = resolveLogDir(options.logDir);
|
|
29344
|
-
const router =
|
|
29448
|
+
const router = import_express3.default.Router();
|
|
29345
29449
|
router.get("/app/trace/:traceId", createGetTraceEntriesHandler(logDir));
|
|
29346
29450
|
router.get("/trace/recent", createGetRecentTracesHandler(logDir));
|
|
29347
29451
|
router.get("/files/:fileName", createGetLogFileHandler(logDir));
|
|
@@ -29384,7 +29488,7 @@ function createDevLogsMiddleware(options = {}) {
|
|
|
29384
29488
|
__name(createDevLogsMiddleware, "createDevLogsMiddleware");
|
|
29385
29489
|
|
|
29386
29490
|
// src/middlewares/collect-logs/router.ts
|
|
29387
|
-
var
|
|
29491
|
+
var import_express4 = __toESM(require_express2(), 1);
|
|
29388
29492
|
|
|
29389
29493
|
// src/middlewares/collect-logs/controller.ts
|
|
29390
29494
|
var import_path = require("path");
|
|
@@ -29483,9 +29587,9 @@ __name(handleError2, "handleError");
|
|
|
29483
29587
|
// src/middlewares/collect-logs/router.ts
|
|
29484
29588
|
function createDevLogRouter2(options = {}) {
|
|
29485
29589
|
const logDir = resolveLogDir2(options.logDir);
|
|
29486
|
-
const router =
|
|
29487
|
-
router.post("/collect",
|
|
29488
|
-
router.post("/collect-batch",
|
|
29590
|
+
const router = import_express4.default.Router();
|
|
29591
|
+
router.post("/collect", import_express4.default.json(), collectLogsHandler(logDir, options.fileName || "client.log"));
|
|
29592
|
+
router.post("/collect-batch", import_express4.default.json(), collectLogsBatchHandler(logDir, options.fileName || "client.log"));
|
|
29489
29593
|
return router;
|
|
29490
29594
|
}
|
|
29491
29595
|
__name(createDevLogRouter2, "createDevLogRouter");
|
|
@@ -29568,7 +29672,15 @@ async function registerMiddlewares(server, middlewares, options) {
|
|
|
29568
29672
|
rootDir: process.cwd(),
|
|
29569
29673
|
...options
|
|
29570
29674
|
};
|
|
29571
|
-
|
|
29675
|
+
const defaultMiddlewares = [];
|
|
29676
|
+
if (context.isDev) {
|
|
29677
|
+
defaultMiddlewares.push(createHealthCheckMiddleware());
|
|
29678
|
+
}
|
|
29679
|
+
const allMiddlewares = [
|
|
29680
|
+
...defaultMiddlewares,
|
|
29681
|
+
...middlewares
|
|
29682
|
+
];
|
|
29683
|
+
for (const middleware of allMiddlewares) {
|
|
29572
29684
|
if (middleware.enabled && !middleware.enabled(context)) {
|
|
29573
29685
|
continue;
|
|
29574
29686
|
}
|
|
@@ -29595,6 +29707,7 @@ __name(registerMiddlewares, "registerMiddlewares");
|
|
|
29595
29707
|
0 && (module.exports = {
|
|
29596
29708
|
createCollectLogsMiddleware,
|
|
29597
29709
|
createDevLogsMiddleware,
|
|
29710
|
+
createHealthCheckMiddleware,
|
|
29598
29711
|
createOpenapiMiddleware,
|
|
29599
29712
|
handleDevProxyError,
|
|
29600
29713
|
normalizeBasePath,
|