@lark-apaas/devtool-kits 1.2.17-alpha.14 → 1.2.17-alpha.15
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/index.cjs +35 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -57
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3297,6 +3297,7 @@ function createSSEHandler(logDir, options = {}) {
|
|
|
3297
3297
|
__name(createSSEHandler, "createSSEHandler");
|
|
3298
3298
|
|
|
3299
3299
|
// src/middlewares/dev-logs/api-list-handler.ts
|
|
3300
|
+
var SERVER_PORT = process.env.SERVER_PORT || "3000";
|
|
3300
3301
|
function extractModuleFromPath(path7) {
|
|
3301
3302
|
const segments = path7.split("/").filter(Boolean);
|
|
3302
3303
|
let startIndex = 0;
|
|
@@ -3322,53 +3323,6 @@ function capitalize(str) {
|
|
|
3322
3323
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
3323
3324
|
}
|
|
3324
3325
|
__name(capitalize, "capitalize");
|
|
3325
|
-
function extractRoutes(app) {
|
|
3326
|
-
const router = app._router;
|
|
3327
|
-
if (!router?.stack) {
|
|
3328
|
-
return [];
|
|
3329
|
-
}
|
|
3330
|
-
const routes = [];
|
|
3331
|
-
const seenRoutes = /* @__PURE__ */ new Set();
|
|
3332
|
-
const processLayer = /* @__PURE__ */ __name((layer, basePath = "") => {
|
|
3333
|
-
if (layer.route) {
|
|
3334
|
-
const path7 = basePath + layer.route.path;
|
|
3335
|
-
if (!path7.includes("/api/") || path7.includes("__framework__") || path7.includes("__innerapi__")) {
|
|
3336
|
-
return;
|
|
3337
|
-
}
|
|
3338
|
-
const methods = Object.keys(layer.route.methods).filter((m) => layer.route.methods[m]);
|
|
3339
|
-
methods.forEach((method) => {
|
|
3340
|
-
const upperMethod = method.toUpperCase();
|
|
3341
|
-
const routeKey = `${upperMethod}:${path7}`;
|
|
3342
|
-
if (seenRoutes.has(routeKey)) {
|
|
3343
|
-
return;
|
|
3344
|
-
}
|
|
3345
|
-
seenRoutes.add(routeKey);
|
|
3346
|
-
const apiPathMatch = path7.match(/\/api\/.*/);
|
|
3347
|
-
const apiPath = apiPathMatch ? apiPathMatch[0] : path7;
|
|
3348
|
-
routes.push({
|
|
3349
|
-
id: generateRouteId(upperMethod, apiPath),
|
|
3350
|
-
path: apiPath,
|
|
3351
|
-
method: upperMethod,
|
|
3352
|
-
module: extractModuleFromPath(apiPath)
|
|
3353
|
-
});
|
|
3354
|
-
});
|
|
3355
|
-
}
|
|
3356
|
-
if (layer.name === "router" && layer.handle?.stack) {
|
|
3357
|
-
let prefix = basePath;
|
|
3358
|
-
if (layer.regexp) {
|
|
3359
|
-
const pattern = new RegExp("^\\^\\\\?(.*?)(?:\\\\/\\?|$)");
|
|
3360
|
-
const match = layer.regexp.source.match(pattern);
|
|
3361
|
-
if (match) {
|
|
3362
|
-
prefix = basePath + match[1].replace(/\\\//g, "/");
|
|
3363
|
-
}
|
|
3364
|
-
}
|
|
3365
|
-
layer.handle.stack.forEach((subLayer) => processLayer(subLayer, prefix));
|
|
3366
|
-
}
|
|
3367
|
-
}, "processLayer");
|
|
3368
|
-
router.stack.forEach((layer) => processLayer(layer));
|
|
3369
|
-
return routes;
|
|
3370
|
-
}
|
|
3371
|
-
__name(extractRoutes, "extractRoutes");
|
|
3372
3326
|
function groupRoutesByModule(routes) {
|
|
3373
3327
|
const groupMap = /* @__PURE__ */ new Map();
|
|
3374
3328
|
routes.forEach((route) => {
|
|
@@ -3387,22 +3341,49 @@ function groupRoutesByModule(routes) {
|
|
|
3387
3341
|
return groups.sort((a, b) => a.name.localeCompare(b.name));
|
|
3388
3342
|
}
|
|
3389
3343
|
__name(groupRoutesByModule, "groupRoutesByModule");
|
|
3344
|
+
async function fetchRoutesFromBackend() {
|
|
3345
|
+
const url = `http://localhost:${SERVER_PORT}/api/__framework__/debug`;
|
|
3346
|
+
const response = await fetch(url, {
|
|
3347
|
+
method: "GET",
|
|
3348
|
+
headers: {
|
|
3349
|
+
"Accept": "application/json"
|
|
3350
|
+
}
|
|
3351
|
+
});
|
|
3352
|
+
if (!response.ok) {
|
|
3353
|
+
throw new Error(`Failed to fetch routes: ${response.status}`);
|
|
3354
|
+
}
|
|
3355
|
+
const data = await response.json();
|
|
3356
|
+
const routeConfig = data["\u8DEF\u7531\u914D\u7F6E"];
|
|
3357
|
+
if (!routeConfig || !routeConfig.routes) {
|
|
3358
|
+
return [];
|
|
3359
|
+
}
|
|
3360
|
+
const debugRoutes = routeConfig.routes;
|
|
3361
|
+
return debugRoutes.filter((route) => {
|
|
3362
|
+
return route.path.startsWith("/api/") && !route.path.includes("__framework__") && !route.path.includes("__innerapi__") && !route.path.startsWith("/api/capability");
|
|
3363
|
+
}).map((route) => ({
|
|
3364
|
+
id: generateRouteId(route.method || "GET", route.path),
|
|
3365
|
+
path: route.path,
|
|
3366
|
+
method: (route.method || "GET").toUpperCase(),
|
|
3367
|
+
module: extractModuleFromPath(route.path)
|
|
3368
|
+
}));
|
|
3369
|
+
}
|
|
3370
|
+
__name(fetchRoutesFromBackend, "fetchRoutesFromBackend");
|
|
3390
3371
|
function createApiListHandler() {
|
|
3391
|
-
return (req, res) => {
|
|
3372
|
+
return async (req, res) => {
|
|
3392
3373
|
res.header("Access-Control-Allow-Origin", "*");
|
|
3393
3374
|
res.header("Access-Control-Allow-Methods", "GET, OPTIONS");
|
|
3394
3375
|
res.header("Access-Control-Allow-Headers", "Content-Type, Accept");
|
|
3395
3376
|
try {
|
|
3396
|
-
const routes =
|
|
3377
|
+
const routes = await fetchRoutesFromBackend();
|
|
3397
3378
|
const groups = groupRoutesByModule(routes);
|
|
3398
3379
|
res.json({
|
|
3399
3380
|
groups,
|
|
3400
3381
|
total: routes.length
|
|
3401
3382
|
});
|
|
3402
3383
|
} catch (error) {
|
|
3403
|
-
console.error("[api-list] Failed to
|
|
3384
|
+
console.error("[api-list] Failed to fetch routes:", error);
|
|
3404
3385
|
res.status(500).json({
|
|
3405
|
-
error: "Failed to
|
|
3386
|
+
error: "Failed to fetch routes",
|
|
3406
3387
|
message: error instanceof Error ? error.message : "Unknown error"
|
|
3407
3388
|
});
|
|
3408
3389
|
}
|
|
@@ -3641,7 +3622,7 @@ function capitalize2(str) {
|
|
|
3641
3622
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
3642
3623
|
}
|
|
3643
3624
|
__name(capitalize2, "capitalize");
|
|
3644
|
-
function
|
|
3625
|
+
function extractRoutes(app) {
|
|
3645
3626
|
const router = app._router;
|
|
3646
3627
|
if (!router?.stack) {
|
|
3647
3628
|
return [];
|
|
@@ -3687,7 +3668,7 @@ function extractRoutes2(app) {
|
|
|
3687
3668
|
router.stack.forEach((layer) => processLayer(layer));
|
|
3688
3669
|
return routes;
|
|
3689
3670
|
}
|
|
3690
|
-
__name(
|
|
3671
|
+
__name(extractRoutes, "extractRoutes");
|
|
3691
3672
|
function groupRoutesByModule2(routes) {
|
|
3692
3673
|
const groupMap = /* @__PURE__ */ new Map();
|
|
3693
3674
|
routes.forEach((route) => {
|
|
@@ -3716,7 +3697,7 @@ function createApiRoutesRouter() {
|
|
|
3716
3697
|
res.header("Access-Control-Allow-Methods", "GET, OPTIONS");
|
|
3717
3698
|
res.header("Access-Control-Allow-Headers", "Content-Type, Accept");
|
|
3718
3699
|
try {
|
|
3719
|
-
const routes =
|
|
3700
|
+
const routes = extractRoutes(req.app);
|
|
3720
3701
|
const groups = groupRoutesByModule2(routes);
|
|
3721
3702
|
res.json({
|
|
3722
3703
|
groups,
|
|
@@ -3786,11 +3767,8 @@ async function registerRouteMiddleware(server, middleware, context) {
|
|
|
3786
3767
|
console.error(`[Middleware] ${middleware.name}: Route middleware must have mountPath. Skipping.`);
|
|
3787
3768
|
return;
|
|
3788
3769
|
}
|
|
3789
|
-
console.log(`[Middleware] Creating router for: ${middleware.name}`);
|
|
3790
3770
|
const router = middleware.createRouter(context);
|
|
3791
|
-
console.log(`[Middleware] Router created for: ${middleware.name}, router stack length: ${router.stack?.length || "unknown"}`);
|
|
3792
3771
|
const fullMountPath = computeMountPath(context.basePath, middleware.mountPath);
|
|
3793
|
-
console.log(`[Middleware] Mounting ${middleware.name} at: ${fullMountPath}`);
|
|
3794
3772
|
server.use(fullMountPath, router);
|
|
3795
3773
|
logMiddlewareRegistration(middleware, fullMountPath);
|
|
3796
3774
|
}
|