@lark-apaas/devtool-kits 1.0.5-alpha.1 → 1.0.5-alpha.3
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 +47 -19
- package/dist/index.cjs +59 -77
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +59 -77
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -22320,10 +22320,10 @@ var require_layer = __commonJS({
|
|
|
22320
22320
|
var require_methods = __commonJS({
|
|
22321
22321
|
"../../../node_modules/methods/index.js"(exports, module) {
|
|
22322
22322
|
"use strict";
|
|
22323
|
-
var
|
|
22323
|
+
var http2 = __require("http");
|
|
22324
22324
|
module.exports = getCurrentNodeMethods() || getBasicNodeMethods();
|
|
22325
22325
|
function getCurrentNodeMethods() {
|
|
22326
|
-
return
|
|
22326
|
+
return http2.METHODS && http2.METHODS.map(/* @__PURE__ */ __name(function lowerCaseMethod(method) {
|
|
22327
22327
|
return method.toLowerCase();
|
|
22328
22328
|
}, "lowerCaseMethod"));
|
|
22329
22329
|
}
|
|
@@ -26001,7 +26001,7 @@ var require_application = __commonJS({
|
|
|
26001
26001
|
var query = require_query();
|
|
26002
26002
|
var debug = require_src3()("express:application");
|
|
26003
26003
|
var View = require_view();
|
|
26004
|
-
var
|
|
26004
|
+
var http2 = __require("http");
|
|
26005
26005
|
var compileETag = require_utils2().compileETag;
|
|
26006
26006
|
var compileQueryParser = require_utils2().compileQueryParser;
|
|
26007
26007
|
var compileTrust = require_utils2().compileTrust;
|
|
@@ -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 = http2.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 http2 = __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(http2.IncomingMessage.prototype);
|
|
26922
26922
|
module.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 http2 = __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(http2.ServerResponse.prototype);
|
|
27364
27364
|
module.exports = res;
|
|
27365
27365
|
var charsetRegExp = /;\s*charset\s*=/;
|
|
27366
27366
|
res.status = /* @__PURE__ */ __name(function status(code) {
|
|
@@ -28394,7 +28394,8 @@ import fs2 from "fs";
|
|
|
28394
28394
|
import path2 from "path";
|
|
28395
28395
|
import { createReadStream } from "fs";
|
|
28396
28396
|
import { createInterface } from "readline";
|
|
28397
|
-
import
|
|
28397
|
+
import http from "http";
|
|
28398
|
+
import https from "https";
|
|
28398
28399
|
var errorHtmlTemplate = null;
|
|
28399
28400
|
function isConnectionError(err) {
|
|
28400
28401
|
const code = err.code;
|
|
@@ -28408,30 +28409,40 @@ function isConnectionError(err) {
|
|
|
28408
28409
|
return connectionErrorCodes.includes(code || "");
|
|
28409
28410
|
}
|
|
28410
28411
|
__name(isConnectionError, "isConnectionError");
|
|
28411
|
-
function checkServiceAvailable(
|
|
28412
|
+
function checkServiceAvailable(targetUrl, timeout = 1e3) {
|
|
28412
28413
|
return new Promise((resolve) => {
|
|
28413
|
-
|
|
28414
|
-
|
|
28415
|
-
|
|
28416
|
-
|
|
28417
|
-
|
|
28418
|
-
|
|
28419
|
-
|
|
28420
|
-
|
|
28421
|
-
|
|
28422
|
-
|
|
28423
|
-
|
|
28424
|
-
|
|
28425
|
-
|
|
28414
|
+
try {
|
|
28415
|
+
const url = new URL(targetUrl);
|
|
28416
|
+
const isHttps = url.protocol === "https:";
|
|
28417
|
+
const httpModule = isHttps ? https : http;
|
|
28418
|
+
const req = httpModule.request({
|
|
28419
|
+
hostname: url.hostname,
|
|
28420
|
+
port: url.port || (isHttps ? 443 : 80),
|
|
28421
|
+
path: "/",
|
|
28422
|
+
method: "HEAD",
|
|
28423
|
+
timeout
|
|
28424
|
+
}, (res) => {
|
|
28425
|
+
const available = res.statusCode !== 502 && !res.headers["x-proxy-error-page"];
|
|
28426
|
+
resolve(available);
|
|
28427
|
+
});
|
|
28428
|
+
req.on("timeout", () => {
|
|
28429
|
+
req.destroy();
|
|
28430
|
+
resolve(false);
|
|
28431
|
+
});
|
|
28432
|
+
req.on("error", () => {
|
|
28433
|
+
resolve(false);
|
|
28434
|
+
});
|
|
28435
|
+
req.end();
|
|
28436
|
+
} catch (e) {
|
|
28426
28437
|
resolve(false);
|
|
28427
|
-
}
|
|
28438
|
+
}
|
|
28428
28439
|
});
|
|
28429
28440
|
}
|
|
28430
28441
|
__name(checkServiceAvailable, "checkServiceAvailable");
|
|
28431
|
-
async function waitForServiceRecovery(
|
|
28442
|
+
async function waitForServiceRecovery(targetUrl, timeout, interval) {
|
|
28432
28443
|
const startTime = Date.now();
|
|
28433
28444
|
while (Date.now() - startTime < timeout) {
|
|
28434
|
-
const isAvailable = await checkServiceAvailable(
|
|
28445
|
+
const isAvailable = await checkServiceAvailable(targetUrl, 2e3);
|
|
28435
28446
|
if (isAvailable) {
|
|
28436
28447
|
return true;
|
|
28437
28448
|
}
|
|
@@ -28534,7 +28545,7 @@ function injectErrorData(template, errorLogs) {
|
|
|
28534
28545
|
}
|
|
28535
28546
|
__name(injectErrorData, "injectErrorData");
|
|
28536
28547
|
function handleDevProxyError(err, req, res, options) {
|
|
28537
|
-
const { logDir = path2.join(process.cwd(), "logs"), maxErrorLogs = 100, logFileName = "server.log", retryTimeout = 5e3, retryInterval = 500, target
|
|
28548
|
+
const { logDir = path2.join(process.cwd(), "logs"), maxErrorLogs = 100, logFileName = "server.log", retryTimeout = 5e3, retryInterval = 500, target } = options || {};
|
|
28538
28549
|
console.error("[Proxy Error]:", err.message);
|
|
28539
28550
|
if (res.headersSent) {
|
|
28540
28551
|
console.error("[Proxy Error]: Headers already sent, cannot send error page");
|
|
@@ -28546,33 +28557,32 @@ function handleDevProxyError(err, req, res, options) {
|
|
|
28546
28557
|
const { logs: errorLogs, hasCompileError } = await readRecentErrorLogs(logDir, maxErrorLogs, logFileName);
|
|
28547
28558
|
if (isConnError && !hasCompileError && target) {
|
|
28548
28559
|
console.log("[Proxy Error]: Connection error without compile errors, possibly server restarting...");
|
|
28549
|
-
let targetUrl = null;
|
|
28550
28560
|
try {
|
|
28551
|
-
|
|
28561
|
+
new URL(target);
|
|
28552
28562
|
} catch (e) {
|
|
28553
28563
|
console.error("[Proxy Error]: Invalid target URL:", target);
|
|
28564
|
+
console.log("[Proxy Error]: Showing error page due to invalid target");
|
|
28554
28565
|
}
|
|
28555
|
-
|
|
28556
|
-
|
|
28557
|
-
|
|
28558
|
-
console.log(
|
|
28559
|
-
|
|
28560
|
-
|
|
28561
|
-
console.log("[Proxy Error]: Service recovered, sending retry response");
|
|
28562
|
-
} else {
|
|
28563
|
-
console.log("[Proxy Error]: Service did not recover within timeout, sending retry response");
|
|
28564
|
-
}
|
|
28566
|
+
console.log(`[Proxy Error]: Waiting for service recovery at ${target} (timeout: ${retryTimeout}ms)...`);
|
|
28567
|
+
const recovered = await waitForServiceRecovery(target, retryTimeout, retryInterval);
|
|
28568
|
+
if (recovered) {
|
|
28569
|
+
console.log("[Proxy Error]: Service recovered within timeout, sending 302 redirect");
|
|
28570
|
+
sendSimpleRedirect(req, res);
|
|
28571
|
+
return;
|
|
28565
28572
|
}
|
|
28566
|
-
|
|
28567
|
-
|
|
28568
|
-
|
|
28573
|
+
console.log("[Proxy Error]: Service did not recover within timeout, showing error page with probe");
|
|
28574
|
+
}
|
|
28575
|
+
if (isConnError && !hasCompileError) {
|
|
28576
|
+
console.log("[Proxy Error]: Showing error page with auto-refresh probe");
|
|
28577
|
+
} else {
|
|
28578
|
+
console.log("[Proxy Error]: Compile error or non-connection error, showing error page");
|
|
28569
28579
|
}
|
|
28570
|
-
console.log("[Proxy Error]: Compile error or non-connection error, showing error page");
|
|
28571
28580
|
const template = getErrorHtmlTemplate();
|
|
28572
28581
|
const html = injectErrorData(template, errorLogs);
|
|
28573
28582
|
res.writeHead(502, {
|
|
28574
28583
|
"Content-Type": "text/html; charset=utf-8",
|
|
28575
|
-
"Cache-Control": "no-cache, no-store, must-revalidate"
|
|
28584
|
+
"Cache-Control": "no-cache, no-store, must-revalidate",
|
|
28585
|
+
"X-Proxy-Error-Page": "true"
|
|
28576
28586
|
});
|
|
28577
28587
|
res.end(html);
|
|
28578
28588
|
} catch (error) {
|
|
@@ -28587,45 +28597,17 @@ function handleDevProxyError(err, req, res, options) {
|
|
|
28587
28597
|
})();
|
|
28588
28598
|
}
|
|
28589
28599
|
__name(handleDevProxyError, "handleDevProxyError");
|
|
28590
|
-
function
|
|
28591
|
-
|
|
28592
|
-
const urlObj = new URL(url, "http://localhost");
|
|
28593
|
-
const retryCount = urlObj.searchParams.get("_retry_count");
|
|
28594
|
-
return retryCount ? parseInt(retryCount, 10) : 0;
|
|
28595
|
-
} catch {
|
|
28596
|
-
return 0;
|
|
28597
|
-
}
|
|
28598
|
-
}
|
|
28599
|
-
__name(getRedirectCount, "getRedirectCount");
|
|
28600
|
-
function addRedirectCount(url, count) {
|
|
28601
|
-
try {
|
|
28602
|
-
const urlObj = new URL(url, "http://localhost");
|
|
28603
|
-
urlObj.searchParams.set("_retry_count", String(count));
|
|
28604
|
-
return urlObj.pathname + urlObj.search;
|
|
28605
|
-
} catch {
|
|
28606
|
-
return url;
|
|
28607
|
-
}
|
|
28608
|
-
}
|
|
28609
|
-
__name(addRedirectCount, "addRedirectCount");
|
|
28610
|
-
function sendSimpleRetryResponse(req, res, maxRedirects) {
|
|
28611
|
-
if (res.headersSent) return true;
|
|
28600
|
+
function sendSimpleRedirect(req, res) {
|
|
28601
|
+
if (res.headersSent) return;
|
|
28612
28602
|
const originalUrl = req.url || "/";
|
|
28613
|
-
|
|
28614
|
-
if (currentCount >= maxRedirects) {
|
|
28615
|
-
console.log(`[Proxy Error]: Max redirects (${maxRedirects}) reached, will show detailed error page`);
|
|
28616
|
-
return false;
|
|
28617
|
-
}
|
|
28618
|
-
const nextCount = currentCount + 1;
|
|
28619
|
-
const redirectUrl = addRedirectCount(originalUrl, nextCount);
|
|
28620
|
-
console.log(`[Proxy Error]: Redirecting (attempt ${nextCount}/${maxRedirects}) to ${redirectUrl}`);
|
|
28603
|
+
console.log("[Proxy Error]: Sending 302 redirect to", originalUrl);
|
|
28621
28604
|
res.writeHead(302, {
|
|
28622
|
-
"Location":
|
|
28605
|
+
"Location": originalUrl,
|
|
28623
28606
|
"Cache-Control": "no-cache, no-store, must-revalidate"
|
|
28624
28607
|
});
|
|
28625
28608
|
res.end();
|
|
28626
|
-
return true;
|
|
28627
28609
|
}
|
|
28628
|
-
__name(
|
|
28610
|
+
__name(sendSimpleRedirect, "sendSimpleRedirect");
|
|
28629
28611
|
|
|
28630
28612
|
// src/middlewares/index.ts
|
|
28631
28613
|
import path5 from "path";
|