@lark-apaas/devtool-kits 1.0.5-alpha.3 → 1.0.5-alpha.5
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 +34 -44
- package/dist/index.cjs +205 -72
- 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 +192 -60
- 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,71 +160,60 @@
|
|
|
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: 'GET',
|
|
169
|
+
const response = await fetch(`${clientBasePath}/dev/health`, {
|
|
170
|
+
method: 'GET',
|
|
173
171
|
cache: 'no-cache',
|
|
174
|
-
redirect: 'manual', //
|
|
175
|
-
signal: controller.signal
|
|
176
|
-
headers: {
|
|
177
|
-
'X-Health-Check': 'true' // 标识这是健康检查请求
|
|
178
|
-
}
|
|
172
|
+
redirect: 'manual', // 不自动跟随重定向
|
|
173
|
+
signal: controller.signal
|
|
179
174
|
});
|
|
180
175
|
|
|
181
176
|
clearTimeout(timeoutId);
|
|
182
177
|
|
|
183
|
-
|
|
184
|
-
const contentType = response.headers.get('content-type') || '';
|
|
185
|
-
const isErrorPage = response.headers.get('x-proxy-error-page') === 'true';
|
|
178
|
+
console.log('[Probe] 状态码:', response.status);
|
|
186
179
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
// 如果收到 302/303 重定向,说明服务正在恢复中,继续探测
|
|
180
|
+
// 如果收到 302/303 重定向,说明代理层正在恢复中,继续探测
|
|
190
181
|
if (response.status === 302 || response.status === 303) {
|
|
191
182
|
console.log('[Probe] 收到重定向响应,服务可能正在恢复,继续探测');
|
|
192
183
|
return;
|
|
193
184
|
}
|
|
194
185
|
|
|
195
|
-
// 如果是 502
|
|
196
|
-
if (response.status === 502
|
|
197
|
-
console.log('[Probe]
|
|
186
|
+
// 如果是 502,说明代理遇到错误,继续探测
|
|
187
|
+
if (response.status === 502) {
|
|
188
|
+
console.log('[Probe] 服务未恢复(502),继续探测');
|
|
198
189
|
return;
|
|
199
190
|
}
|
|
200
191
|
|
|
201
|
-
// 如果是 200
|
|
192
|
+
// 如果是 200,解析健康检查结果
|
|
202
193
|
if (response.status === 200) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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, '继续探测');
|
|
216
213
|
}
|
|
217
|
-
|
|
218
|
-
//
|
|
219
|
-
console.log('[Probe]
|
|
220
|
-
stopServiceProbe();
|
|
221
|
-
|
|
222
|
-
// 延迟一小段时间后刷新,让日志输出完整
|
|
223
|
-
setTimeout(() => {
|
|
224
|
-
console.log('[Probe] 刷新页面...');
|
|
225
|
-
window.location.href = currentUrl;
|
|
226
|
-
}, 300);
|
|
214
|
+
} else if (response.status === 503) {
|
|
215
|
+
// 503 表示服务不健康,继续探测
|
|
216
|
+
console.log('[Probe] 服务不健康(503),继续探测');
|
|
227
217
|
} else {
|
|
228
218
|
console.log('[Probe] 收到非预期状态码:', response.status, '继续探测');
|
|
229
219
|
}
|
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,
|
|
@@ -28405,8 +28406,6 @@ __name(collapseExtraBlankLines, "collapseExtraBlankLines");
|
|
|
28405
28406
|
// src/helpers/proxy-error/index.ts
|
|
28406
28407
|
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
28407
28408
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
28408
|
-
var import_node_fs3 = require("fs");
|
|
28409
|
-
var import_node_readline = require("readline");
|
|
28410
28409
|
var import_node_http = __toESM(require("http"), 1);
|
|
28411
28410
|
var import_node_https = __toESM(require("https"), 1);
|
|
28412
28411
|
var errorHtmlTemplate = null;
|
|
@@ -28482,63 +28481,82 @@ function parseLogLine(line) {
|
|
|
28482
28481
|
if (!trimmed) return null;
|
|
28483
28482
|
const match = trimmed.match(/^\[\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\]\s+\[server\]\s+(.*)$/);
|
|
28484
28483
|
if (match) {
|
|
28485
|
-
|
|
28484
|
+
const content = match[1].trim();
|
|
28485
|
+
return content || null;
|
|
28486
28486
|
}
|
|
28487
|
-
return
|
|
28487
|
+
return null;
|
|
28488
28488
|
}
|
|
28489
28489
|
__name(parseLogLine, "parseLogLine");
|
|
28490
28490
|
async function readRecentErrorLogs(logDir, maxLogs, fileName) {
|
|
28491
28491
|
const logFilePath = import_node_path2.default.join(logDir, fileName);
|
|
28492
|
+
let fileStats;
|
|
28492
28493
|
try {
|
|
28493
|
-
await import_node_fs2.default.promises.
|
|
28494
|
+
fileStats = await import_node_fs2.default.promises.stat(logFilePath);
|
|
28494
28495
|
} catch {
|
|
28495
28496
|
return {
|
|
28496
28497
|
logs: [],
|
|
28497
28498
|
hasCompileError: false
|
|
28498
28499
|
};
|
|
28499
28500
|
}
|
|
28500
|
-
const
|
|
28501
|
-
const
|
|
28502
|
-
|
|
28503
|
-
|
|
28504
|
-
const
|
|
28505
|
-
|
|
28506
|
-
crlfDelay: Infinity
|
|
28507
|
-
});
|
|
28501
|
+
const fileSize = fileStats.size;
|
|
28502
|
+
const maxReadSize = 1024 * 1024;
|
|
28503
|
+
const readSize = Math.min(fileSize, maxReadSize);
|
|
28504
|
+
const startPosition = Math.max(0, fileSize - readSize);
|
|
28505
|
+
const buffer = Buffer.allocUnsafe(readSize);
|
|
28506
|
+
let fileHandle;
|
|
28508
28507
|
try {
|
|
28509
|
-
|
|
28510
|
-
|
|
28511
|
-
|
|
28512
|
-
|
|
28513
|
-
|
|
28514
|
-
|
|
28508
|
+
fileHandle = await import_node_fs2.default.promises.open(logFilePath, "r");
|
|
28509
|
+
await fileHandle.read(buffer, 0, readSize, startPosition);
|
|
28510
|
+
} catch (error) {
|
|
28511
|
+
console.error("[Proxy Error]: Failed to read log file:", error);
|
|
28512
|
+
return {
|
|
28513
|
+
logs: [],
|
|
28514
|
+
hasCompileError: false
|
|
28515
|
+
};
|
|
28515
28516
|
} finally {
|
|
28516
|
-
|
|
28517
|
-
|
|
28517
|
+
if (fileHandle) {
|
|
28518
|
+
await fileHandle.close();
|
|
28519
|
+
}
|
|
28520
|
+
}
|
|
28521
|
+
const content = buffer.toString("utf8");
|
|
28522
|
+
const lines = content.split("\n");
|
|
28523
|
+
if (startPosition > 0 && lines.length > 0) {
|
|
28524
|
+
lines.shift();
|
|
28525
|
+
}
|
|
28526
|
+
const allLines = [];
|
|
28527
|
+
for (const line of lines) {
|
|
28528
|
+
const parsed = parseLogLine(line);
|
|
28529
|
+
if (parsed !== null) {
|
|
28530
|
+
allLines.push(parsed);
|
|
28531
|
+
}
|
|
28518
28532
|
}
|
|
28519
28533
|
let startIndex = -1;
|
|
28520
28534
|
for (let i = allLines.length - 1; i >= 0; i--) {
|
|
28521
|
-
|
|
28535
|
+
const line = allLines[i];
|
|
28536
|
+
if (line.includes("Starting compilation in watch mode") || line.includes("File change detected. Starting incremental compilation")) {
|
|
28522
28537
|
startIndex = i;
|
|
28523
28538
|
break;
|
|
28524
28539
|
}
|
|
28525
28540
|
}
|
|
28526
28541
|
if (startIndex === -1) {
|
|
28542
|
+
console.log("[Proxy Error]: No compilation start marker found, returning last logs");
|
|
28543
|
+
const fallbackLogs = allLines.slice(-maxLogs);
|
|
28544
|
+
const hasCompileError2 = checkForErrors(fallbackLogs);
|
|
28527
28545
|
return {
|
|
28528
|
-
logs:
|
|
28529
|
-
hasCompileError:
|
|
28546
|
+
logs: fallbackLogs,
|
|
28547
|
+
hasCompileError: hasCompileError2
|
|
28530
28548
|
};
|
|
28531
28549
|
}
|
|
28532
28550
|
let endIndex = allLines.length;
|
|
28533
|
-
let
|
|
28534
|
-
|
|
28535
|
-
if (
|
|
28536
|
-
endIndex = i
|
|
28537
|
-
hasCompileError = true;
|
|
28551
|
+
for (let i = startIndex + 1; i < allLines.length; i++) {
|
|
28552
|
+
const line = allLines[i];
|
|
28553
|
+
if (line.includes("Starting compilation in watch mode") || line.includes("File change detected. Starting incremental compilation")) {
|
|
28554
|
+
endIndex = i;
|
|
28538
28555
|
break;
|
|
28539
28556
|
}
|
|
28540
28557
|
}
|
|
28541
28558
|
const errorSection = allLines.slice(startIndex, endIndex);
|
|
28559
|
+
const hasCompileError = checkForErrors(errorSection);
|
|
28542
28560
|
const logs = errorSection.length > maxLogs ? errorSection.slice(-maxLogs) : errorSection;
|
|
28543
28561
|
return {
|
|
28544
28562
|
logs,
|
|
@@ -28546,7 +28564,21 @@ async function readRecentErrorLogs(logDir, maxLogs, fileName) {
|
|
|
28546
28564
|
};
|
|
28547
28565
|
}
|
|
28548
28566
|
__name(readRecentErrorLogs, "readRecentErrorLogs");
|
|
28549
|
-
function
|
|
28567
|
+
function checkForErrors(logs) {
|
|
28568
|
+
for (const line of logs) {
|
|
28569
|
+
const compileErrorMatch = line.match(/Found (\d+) errors?\. Watching for file changes/);
|
|
28570
|
+
if (compileErrorMatch) {
|
|
28571
|
+
const errorCount = parseInt(compileErrorMatch[1], 10);
|
|
28572
|
+
if (errorCount > 0) {
|
|
28573
|
+
console.log(`[Proxy Error]: Found ${errorCount} compilation error(s)`);
|
|
28574
|
+
return true;
|
|
28575
|
+
}
|
|
28576
|
+
}
|
|
28577
|
+
}
|
|
28578
|
+
return false;
|
|
28579
|
+
}
|
|
28580
|
+
__name(checkForErrors, "checkForErrors");
|
|
28581
|
+
function injectErrorData(template, errorLogs, clientBasePath) {
|
|
28550
28582
|
let logsText = "";
|
|
28551
28583
|
if (errorLogs.length > 0) {
|
|
28552
28584
|
logsText = errorLogs.join("\n");
|
|
@@ -28554,11 +28586,12 @@ function injectErrorData(template, errorLogs) {
|
|
|
28554
28586
|
logsText = "\u672A\u627E\u5230\u76F8\u5173\u9519\u8BEF\u65E5\u5FD7";
|
|
28555
28587
|
}
|
|
28556
28588
|
return template.replace("{{.errorData.message}}", `\u670D\u52A1\u542F\u52A8\u5F02\u5E38\uFF0C\u8BF7\u6839\u636E\u65E5\u5FD7\u4FEE\u590D\u76F8\u5173\u95EE\u9898
|
|
28557
|
-
${JSON.stringify(logsText)}`);
|
|
28589
|
+
${JSON.stringify(logsText)}`).replace("{{.clientBasePath}}", clientBasePath);
|
|
28558
28590
|
}
|
|
28559
28591
|
__name(injectErrorData, "injectErrorData");
|
|
28560
28592
|
function handleDevProxyError(err, req, res, options) {
|
|
28561
|
-
const { logDir = import_node_path2.default.join(process.cwd(), "logs"), maxErrorLogs = 100, logFileName = "server.log", retryTimeout = 5e3, retryInterval = 500, target } = options || {};
|
|
28593
|
+
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 || {};
|
|
28594
|
+
const clientBasePathWithoutSlash = normalizeBasePath(clientBasePath);
|
|
28562
28595
|
console.error("[Proxy Error]:", err.message);
|
|
28563
28596
|
if (res.headersSent) {
|
|
28564
28597
|
console.error("[Proxy Error]: Headers already sent, cannot send error page");
|
|
@@ -28591,7 +28624,7 @@ function handleDevProxyError(err, req, res, options) {
|
|
|
28591
28624
|
console.log("[Proxy Error]: Compile error or non-connection error, showing error page");
|
|
28592
28625
|
}
|
|
28593
28626
|
const template = getErrorHtmlTemplate();
|
|
28594
|
-
const html = injectErrorData(template, errorLogs);
|
|
28627
|
+
const html = injectErrorData(template, errorLogs, clientBasePathWithoutSlash);
|
|
28595
28628
|
res.writeHead(502, {
|
|
28596
28629
|
"Content-Type": "text/html; charset=utf-8",
|
|
28597
28630
|
"Cache-Control": "no-cache, no-store, must-revalidate",
|
|
@@ -28625,25 +28658,116 @@ __name(sendSimpleRedirect, "sendSimpleRedirect");
|
|
|
28625
28658
|
// src/middlewares/index.ts
|
|
28626
28659
|
var import_node_path8 = __toESM(require("path"), 1);
|
|
28627
28660
|
|
|
28628
|
-
// src/middlewares/
|
|
28661
|
+
// src/middlewares/health-check/router.ts
|
|
28629
28662
|
var import_express = __toESM(require_express2(), 1);
|
|
28663
|
+
var import_node_http2 = __toESM(require("http"), 1);
|
|
28664
|
+
function checkServiceHealth(host, port, timeout) {
|
|
28665
|
+
return new Promise((resolve) => {
|
|
28666
|
+
const startTime = Date.now();
|
|
28667
|
+
const req = import_node_http2.default.request({
|
|
28668
|
+
hostname: host,
|
|
28669
|
+
port,
|
|
28670
|
+
path: "/",
|
|
28671
|
+
method: "HEAD",
|
|
28672
|
+
timeout
|
|
28673
|
+
}, (_res) => {
|
|
28674
|
+
const responseTime = Date.now() - startTime;
|
|
28675
|
+
resolve({
|
|
28676
|
+
available: true,
|
|
28677
|
+
responseTime
|
|
28678
|
+
});
|
|
28679
|
+
});
|
|
28680
|
+
req.on("timeout", () => {
|
|
28681
|
+
req.destroy();
|
|
28682
|
+
resolve({
|
|
28683
|
+
available: false,
|
|
28684
|
+
error: "Request timeout"
|
|
28685
|
+
});
|
|
28686
|
+
});
|
|
28687
|
+
req.on("error", (err) => {
|
|
28688
|
+
resolve({
|
|
28689
|
+
available: false,
|
|
28690
|
+
error: err.message
|
|
28691
|
+
});
|
|
28692
|
+
});
|
|
28693
|
+
req.end();
|
|
28694
|
+
});
|
|
28695
|
+
}
|
|
28696
|
+
__name(checkServiceHealth, "checkServiceHealth");
|
|
28697
|
+
function createHealthCheckRouter(options = {}) {
|
|
28698
|
+
const { targetPort = Number(process.env.SERVER_PORT) || 3e3, targetHost = "localhost", timeout = 2e3 } = options;
|
|
28699
|
+
const router = (0, import_express.Router)();
|
|
28700
|
+
router.get("/", async (_req, res) => {
|
|
28701
|
+
try {
|
|
28702
|
+
const result = await checkServiceHealth(targetHost, targetPort, timeout);
|
|
28703
|
+
if (result.available) {
|
|
28704
|
+
res.status(200).json({
|
|
28705
|
+
status: "healthy",
|
|
28706
|
+
service: `${targetHost}:${targetPort}`,
|
|
28707
|
+
responseTime: result.responseTime,
|
|
28708
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
28709
|
+
});
|
|
28710
|
+
} else {
|
|
28711
|
+
res.status(503).json({
|
|
28712
|
+
status: "unhealthy",
|
|
28713
|
+
service: `${targetHost}:${targetPort}`,
|
|
28714
|
+
error: result.error,
|
|
28715
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
28716
|
+
});
|
|
28717
|
+
}
|
|
28718
|
+
} catch (error) {
|
|
28719
|
+
res.status(500).json({
|
|
28720
|
+
status: "error",
|
|
28721
|
+
service: `${targetHost}:${targetPort}`,
|
|
28722
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
28723
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
28724
|
+
});
|
|
28725
|
+
}
|
|
28726
|
+
});
|
|
28727
|
+
return router;
|
|
28728
|
+
}
|
|
28729
|
+
__name(createHealthCheckRouter, "createHealthCheckRouter");
|
|
28730
|
+
|
|
28731
|
+
// src/middlewares/health-check/index.ts
|
|
28732
|
+
var HEALTH_CHECK_ROUTES = [
|
|
28733
|
+
{
|
|
28734
|
+
method: "GET",
|
|
28735
|
+
path: "/",
|
|
28736
|
+
description: "Check if target service is healthy and available"
|
|
28737
|
+
}
|
|
28738
|
+
];
|
|
28739
|
+
function createHealthCheckMiddleware(options = {}) {
|
|
28740
|
+
return {
|
|
28741
|
+
name: "health-check",
|
|
28742
|
+
mountPath: "/dev/health",
|
|
28743
|
+
routes: HEALTH_CHECK_ROUTES,
|
|
28744
|
+
enabled: /* @__PURE__ */ __name((context) => context.isDev, "enabled"),
|
|
28745
|
+
createRouter: /* @__PURE__ */ __name((_context) => {
|
|
28746
|
+
return createHealthCheckRouter(options);
|
|
28747
|
+
}, "createRouter")
|
|
28748
|
+
};
|
|
28749
|
+
}
|
|
28750
|
+
__name(createHealthCheckMiddleware, "createHealthCheckMiddleware");
|
|
28751
|
+
|
|
28752
|
+
// src/middlewares/openapi/router.ts
|
|
28753
|
+
var import_express2 = __toESM(require_express2(), 1);
|
|
28630
28754
|
|
|
28631
28755
|
// src/middlewares/openapi/controller.ts
|
|
28632
28756
|
var import_promises = __toESM(require("fs/promises"), 1);
|
|
28633
28757
|
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
28634
28758
|
|
|
28635
28759
|
// src/middlewares/openapi/services.ts
|
|
28636
|
-
var
|
|
28760
|
+
var import_node_fs4 = require("fs");
|
|
28637
28761
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
28638
28762
|
var import_typescript = __toESM(require("typescript"), 1);
|
|
28639
28763
|
|
|
28640
28764
|
// src/middlewares/openapi/utils.ts
|
|
28641
28765
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
28642
|
-
var
|
|
28766
|
+
var import_node_fs3 = require("fs");
|
|
28643
28767
|
async function findControllerFiles(dir) {
|
|
28644
28768
|
const files = [];
|
|
28645
28769
|
async function scan(currentDir) {
|
|
28646
|
-
const entries = await
|
|
28770
|
+
const entries = await import_node_fs3.promises.readdir(currentDir, {
|
|
28647
28771
|
withFileTypes: true
|
|
28648
28772
|
});
|
|
28649
28773
|
for (const entry of entries) {
|
|
@@ -28727,14 +28851,14 @@ async function enhanceOpenApiWithSourceInfo(options = {}) {
|
|
|
28727
28851
|
if (options.openapiData) {
|
|
28728
28852
|
openapi = JSON.parse(JSON.stringify(options.openapiData));
|
|
28729
28853
|
} else {
|
|
28730
|
-
const openapiContent = await
|
|
28854
|
+
const openapiContent = await import_node_fs4.promises.readFile(openapiPath, "utf-8");
|
|
28731
28855
|
openapi = JSON.parse(openapiContent);
|
|
28732
28856
|
}
|
|
28733
28857
|
const controllerFiles = await findControllerFiles(serverDir);
|
|
28734
28858
|
const sourceMap = await buildSourceMap(controllerFiles, processControllerFile);
|
|
28735
28859
|
const enhanced = enhanceOpenApiPaths(openapi, sourceMap);
|
|
28736
28860
|
if (writeFile) {
|
|
28737
|
-
await
|
|
28861
|
+
await import_node_fs4.promises.writeFile(openapiPath, JSON.stringify(openapi, null, 2) + "\n", "utf-8");
|
|
28738
28862
|
}
|
|
28739
28863
|
const duration = Date.now() - startTime;
|
|
28740
28864
|
return {
|
|
@@ -28750,7 +28874,7 @@ async function enhanceOpenApiWithSourceInfo(options = {}) {
|
|
|
28750
28874
|
__name(enhanceOpenApiWithSourceInfo, "enhanceOpenApiWithSourceInfo");
|
|
28751
28875
|
async function processControllerFile(filePath) {
|
|
28752
28876
|
const relativePath = import_node_path4.default.relative(process.cwd(), filePath);
|
|
28753
|
-
const content = await
|
|
28877
|
+
const content = await import_node_fs4.promises.readFile(filePath, "utf-8");
|
|
28754
28878
|
const sourceFile = import_typescript.default.createSourceFile(filePath, content, import_typescript.default.ScriptTarget.Latest, true);
|
|
28755
28879
|
return extractControllerMetadata(sourceFile, relativePath);
|
|
28756
28880
|
}
|
|
@@ -28873,7 +28997,7 @@ __name(createOpenapiHandler, "createOpenapiHandler");
|
|
|
28873
28997
|
// src/middlewares/openapi/router.ts
|
|
28874
28998
|
function createOpenapiRouter(options, context) {
|
|
28875
28999
|
const { openapiFilePath, enableEnhancement, serverDir } = options;
|
|
28876
|
-
const router =
|
|
29000
|
+
const router = import_express2.default.Router();
|
|
28877
29001
|
const handler = createOpenapiHandler(openapiFilePath, enableEnhancement, serverDir);
|
|
28878
29002
|
router.get("/openapi.json", (req, res) => handler(req, res, context));
|
|
28879
29003
|
return router;
|
|
@@ -28907,10 +29031,10 @@ function createOpenapiMiddleware(options) {
|
|
|
28907
29031
|
__name(createOpenapiMiddleware, "createOpenapiMiddleware");
|
|
28908
29032
|
|
|
28909
29033
|
// src/middlewares/dev-logs/router.ts
|
|
28910
|
-
var
|
|
29034
|
+
var import_express3 = __toESM(require_express2(), 1);
|
|
28911
29035
|
|
|
28912
29036
|
// src/middlewares/dev-logs/utils.ts
|
|
28913
|
-
var
|
|
29037
|
+
var import_node_fs5 = require("fs");
|
|
28914
29038
|
var import_node_path5 = require("path");
|
|
28915
29039
|
|
|
28916
29040
|
// src/middlewares/dev-logs/helper/path-matcher.ts
|
|
@@ -28962,7 +29086,7 @@ function getRelativePath(filePath) {
|
|
|
28962
29086
|
__name(getRelativePath, "getRelativePath");
|
|
28963
29087
|
async function fileExists(filePath) {
|
|
28964
29088
|
try {
|
|
28965
|
-
await
|
|
29089
|
+
await import_node_fs5.promises.access(filePath);
|
|
28966
29090
|
return true;
|
|
28967
29091
|
} catch {
|
|
28968
29092
|
return false;
|
|
@@ -29045,18 +29169,18 @@ __name(serializeError, "serializeError");
|
|
|
29045
29169
|
var import_node_path6 = require("path");
|
|
29046
29170
|
|
|
29047
29171
|
// src/middlewares/dev-logs/services.ts
|
|
29048
|
-
var
|
|
29049
|
-
var
|
|
29172
|
+
var import_node_fs6 = require("fs");
|
|
29173
|
+
var import_node_readline = require("readline");
|
|
29050
29174
|
async function readLogEntriesByTrace(filePath, traceId, limit) {
|
|
29051
29175
|
const exists = await fileExists(filePath);
|
|
29052
29176
|
if (!exists) {
|
|
29053
29177
|
return void 0;
|
|
29054
29178
|
}
|
|
29055
29179
|
const matches = [];
|
|
29056
|
-
const stream = (0,
|
|
29180
|
+
const stream = (0, import_node_fs6.createReadStream)(filePath, {
|
|
29057
29181
|
encoding: "utf8"
|
|
29058
29182
|
});
|
|
29059
|
-
const rl = (0,
|
|
29183
|
+
const rl = (0, import_node_readline.createInterface)({
|
|
29060
29184
|
input: stream,
|
|
29061
29185
|
crlfDelay: Infinity
|
|
29062
29186
|
});
|
|
@@ -29145,7 +29269,7 @@ async function readRecentTraceCalls(filePath, page, pageSize, pathFilter, method
|
|
|
29145
29269
|
}
|
|
29146
29270
|
__name(readRecentTraceCalls, "readRecentTraceCalls");
|
|
29147
29271
|
async function readFileReverse(filePath, chunkSize, processLine) {
|
|
29148
|
-
const handle = await
|
|
29272
|
+
const handle = await import_node_fs6.promises.open(filePath, "r");
|
|
29149
29273
|
try {
|
|
29150
29274
|
const stats = await handle.stat();
|
|
29151
29275
|
let position = stats.size;
|
|
@@ -29207,10 +29331,10 @@ async function readLogFilePage(filePath, page, pageSize) {
|
|
|
29207
29331
|
const capacity = page * pageSize;
|
|
29208
29332
|
const buffer = [];
|
|
29209
29333
|
let totalLines = 0;
|
|
29210
|
-
const stream = (0,
|
|
29334
|
+
const stream = (0, import_node_fs6.createReadStream)(filePath, {
|
|
29211
29335
|
encoding: "utf8"
|
|
29212
29336
|
});
|
|
29213
|
-
const rl = (0,
|
|
29337
|
+
const rl = (0, import_node_readline.createInterface)({
|
|
29214
29338
|
input: stream,
|
|
29215
29339
|
crlfDelay: Infinity
|
|
29216
29340
|
});
|
|
@@ -29352,7 +29476,7 @@ __name(createGetLogFileHandler, "createGetLogFileHandler");
|
|
|
29352
29476
|
// src/middlewares/dev-logs/router.ts
|
|
29353
29477
|
function createDevLogRouter(options = {}) {
|
|
29354
29478
|
const logDir = resolveLogDir(options.logDir);
|
|
29355
|
-
const router =
|
|
29479
|
+
const router = import_express3.default.Router();
|
|
29356
29480
|
router.get("/app/trace/:traceId", createGetTraceEntriesHandler(logDir));
|
|
29357
29481
|
router.get("/trace/recent", createGetRecentTracesHandler(logDir));
|
|
29358
29482
|
router.get("/files/:fileName", createGetLogFileHandler(logDir));
|
|
@@ -29395,7 +29519,7 @@ function createDevLogsMiddleware(options = {}) {
|
|
|
29395
29519
|
__name(createDevLogsMiddleware, "createDevLogsMiddleware");
|
|
29396
29520
|
|
|
29397
29521
|
// src/middlewares/collect-logs/router.ts
|
|
29398
|
-
var
|
|
29522
|
+
var import_express4 = __toESM(require_express2(), 1);
|
|
29399
29523
|
|
|
29400
29524
|
// src/middlewares/collect-logs/controller.ts
|
|
29401
29525
|
var import_path = require("path");
|
|
@@ -29403,7 +29527,7 @@ var import_fs = __toESM(require("fs"), 1);
|
|
|
29403
29527
|
|
|
29404
29528
|
// src/middlewares/collect-logs/utils.ts
|
|
29405
29529
|
var import_node_path7 = require("path");
|
|
29406
|
-
var
|
|
29530
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
29407
29531
|
function resolveLogDir2(provided) {
|
|
29408
29532
|
if (!provided) {
|
|
29409
29533
|
return (0, import_node_path7.join)(process.cwd(), "logs");
|
|
@@ -29412,8 +29536,8 @@ function resolveLogDir2(provided) {
|
|
|
29412
29536
|
}
|
|
29413
29537
|
__name(resolveLogDir2, "resolveLogDir");
|
|
29414
29538
|
function ensureDir(dir) {
|
|
29415
|
-
if (!
|
|
29416
|
-
|
|
29539
|
+
if (!import_node_fs7.default.existsSync(dir)) {
|
|
29540
|
+
import_node_fs7.default.mkdirSync(dir, {
|
|
29417
29541
|
recursive: true
|
|
29418
29542
|
});
|
|
29419
29543
|
}
|
|
@@ -29494,9 +29618,9 @@ __name(handleError2, "handleError");
|
|
|
29494
29618
|
// src/middlewares/collect-logs/router.ts
|
|
29495
29619
|
function createDevLogRouter2(options = {}) {
|
|
29496
29620
|
const logDir = resolveLogDir2(options.logDir);
|
|
29497
|
-
const router =
|
|
29498
|
-
router.post("/collect",
|
|
29499
|
-
router.post("/collect-batch",
|
|
29621
|
+
const router = import_express4.default.Router();
|
|
29622
|
+
router.post("/collect", import_express4.default.json(), collectLogsHandler(logDir, options.fileName || "client.log"));
|
|
29623
|
+
router.post("/collect-batch", import_express4.default.json(), collectLogsBatchHandler(logDir, options.fileName || "client.log"));
|
|
29500
29624
|
return router;
|
|
29501
29625
|
}
|
|
29502
29626
|
__name(createDevLogRouter2, "createDevLogRouter");
|
|
@@ -29579,7 +29703,15 @@ async function registerMiddlewares(server, middlewares, options) {
|
|
|
29579
29703
|
rootDir: process.cwd(),
|
|
29580
29704
|
...options
|
|
29581
29705
|
};
|
|
29582
|
-
|
|
29706
|
+
const defaultMiddlewares = [];
|
|
29707
|
+
if (context.isDev) {
|
|
29708
|
+
defaultMiddlewares.push(createHealthCheckMiddleware());
|
|
29709
|
+
}
|
|
29710
|
+
const allMiddlewares = [
|
|
29711
|
+
...defaultMiddlewares,
|
|
29712
|
+
...middlewares
|
|
29713
|
+
];
|
|
29714
|
+
for (const middleware of allMiddlewares) {
|
|
29583
29715
|
if (middleware.enabled && !middleware.enabled(context)) {
|
|
29584
29716
|
continue;
|
|
29585
29717
|
}
|
|
@@ -29606,6 +29738,7 @@ __name(registerMiddlewares, "registerMiddlewares");
|
|
|
29606
29738
|
0 && (module.exports = {
|
|
29607
29739
|
createCollectLogsMiddleware,
|
|
29608
29740
|
createDevLogsMiddleware,
|
|
29741
|
+
createHealthCheckMiddleware,
|
|
29609
29742
|
createOpenapiMiddleware,
|
|
29610
29743
|
handleDevProxyError,
|
|
29611
29744
|
normalizeBasePath,
|