@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.js
CHANGED
|
@@ -3255,6 +3255,7 @@ function createSSEHandler(logDir, options = {}) {
|
|
|
3255
3255
|
__name(createSSEHandler, "createSSEHandler");
|
|
3256
3256
|
|
|
3257
3257
|
// src/middlewares/dev-logs/api-list-handler.ts
|
|
3258
|
+
var SERVER_PORT = process.env.SERVER_PORT || "3000";
|
|
3258
3259
|
function extractModuleFromPath(path7) {
|
|
3259
3260
|
const segments = path7.split("/").filter(Boolean);
|
|
3260
3261
|
let startIndex = 0;
|
|
@@ -3280,53 +3281,6 @@ function capitalize(str) {
|
|
|
3280
3281
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
3281
3282
|
}
|
|
3282
3283
|
__name(capitalize, "capitalize");
|
|
3283
|
-
function extractRoutes(app) {
|
|
3284
|
-
const router = app._router;
|
|
3285
|
-
if (!router?.stack) {
|
|
3286
|
-
return [];
|
|
3287
|
-
}
|
|
3288
|
-
const routes = [];
|
|
3289
|
-
const seenRoutes = /* @__PURE__ */ new Set();
|
|
3290
|
-
const processLayer = /* @__PURE__ */ __name((layer, basePath = "") => {
|
|
3291
|
-
if (layer.route) {
|
|
3292
|
-
const path7 = basePath + layer.route.path;
|
|
3293
|
-
if (!path7.includes("/api/") || path7.includes("__framework__") || path7.includes("__innerapi__")) {
|
|
3294
|
-
return;
|
|
3295
|
-
}
|
|
3296
|
-
const methods = Object.keys(layer.route.methods).filter((m) => layer.route.methods[m]);
|
|
3297
|
-
methods.forEach((method) => {
|
|
3298
|
-
const upperMethod = method.toUpperCase();
|
|
3299
|
-
const routeKey = `${upperMethod}:${path7}`;
|
|
3300
|
-
if (seenRoutes.has(routeKey)) {
|
|
3301
|
-
return;
|
|
3302
|
-
}
|
|
3303
|
-
seenRoutes.add(routeKey);
|
|
3304
|
-
const apiPathMatch = path7.match(/\/api\/.*/);
|
|
3305
|
-
const apiPath = apiPathMatch ? apiPathMatch[0] : path7;
|
|
3306
|
-
routes.push({
|
|
3307
|
-
id: generateRouteId(upperMethod, apiPath),
|
|
3308
|
-
path: apiPath,
|
|
3309
|
-
method: upperMethod,
|
|
3310
|
-
module: extractModuleFromPath(apiPath)
|
|
3311
|
-
});
|
|
3312
|
-
});
|
|
3313
|
-
}
|
|
3314
|
-
if (layer.name === "router" && layer.handle?.stack) {
|
|
3315
|
-
let prefix = basePath;
|
|
3316
|
-
if (layer.regexp) {
|
|
3317
|
-
const pattern = new RegExp("^\\^\\\\?(.*?)(?:\\\\/\\?|$)");
|
|
3318
|
-
const match = layer.regexp.source.match(pattern);
|
|
3319
|
-
if (match) {
|
|
3320
|
-
prefix = basePath + match[1].replace(/\\\//g, "/");
|
|
3321
|
-
}
|
|
3322
|
-
}
|
|
3323
|
-
layer.handle.stack.forEach((subLayer) => processLayer(subLayer, prefix));
|
|
3324
|
-
}
|
|
3325
|
-
}, "processLayer");
|
|
3326
|
-
router.stack.forEach((layer) => processLayer(layer));
|
|
3327
|
-
return routes;
|
|
3328
|
-
}
|
|
3329
|
-
__name(extractRoutes, "extractRoutes");
|
|
3330
3284
|
function groupRoutesByModule(routes) {
|
|
3331
3285
|
const groupMap = /* @__PURE__ */ new Map();
|
|
3332
3286
|
routes.forEach((route) => {
|
|
@@ -3345,22 +3299,49 @@ function groupRoutesByModule(routes) {
|
|
|
3345
3299
|
return groups.sort((a, b) => a.name.localeCompare(b.name));
|
|
3346
3300
|
}
|
|
3347
3301
|
__name(groupRoutesByModule, "groupRoutesByModule");
|
|
3302
|
+
async function fetchRoutesFromBackend() {
|
|
3303
|
+
const url = `http://localhost:${SERVER_PORT}/api/__framework__/debug`;
|
|
3304
|
+
const response = await fetch(url, {
|
|
3305
|
+
method: "GET",
|
|
3306
|
+
headers: {
|
|
3307
|
+
"Accept": "application/json"
|
|
3308
|
+
}
|
|
3309
|
+
});
|
|
3310
|
+
if (!response.ok) {
|
|
3311
|
+
throw new Error(`Failed to fetch routes: ${response.status}`);
|
|
3312
|
+
}
|
|
3313
|
+
const data = await response.json();
|
|
3314
|
+
const routeConfig = data["\u8DEF\u7531\u914D\u7F6E"];
|
|
3315
|
+
if (!routeConfig || !routeConfig.routes) {
|
|
3316
|
+
return [];
|
|
3317
|
+
}
|
|
3318
|
+
const debugRoutes = routeConfig.routes;
|
|
3319
|
+
return debugRoutes.filter((route) => {
|
|
3320
|
+
return route.path.startsWith("/api/") && !route.path.includes("__framework__") && !route.path.includes("__innerapi__") && !route.path.startsWith("/api/capability");
|
|
3321
|
+
}).map((route) => ({
|
|
3322
|
+
id: generateRouteId(route.method || "GET", route.path),
|
|
3323
|
+
path: route.path,
|
|
3324
|
+
method: (route.method || "GET").toUpperCase(),
|
|
3325
|
+
module: extractModuleFromPath(route.path)
|
|
3326
|
+
}));
|
|
3327
|
+
}
|
|
3328
|
+
__name(fetchRoutesFromBackend, "fetchRoutesFromBackend");
|
|
3348
3329
|
function createApiListHandler() {
|
|
3349
|
-
return (req, res) => {
|
|
3330
|
+
return async (req, res) => {
|
|
3350
3331
|
res.header("Access-Control-Allow-Origin", "*");
|
|
3351
3332
|
res.header("Access-Control-Allow-Methods", "GET, OPTIONS");
|
|
3352
3333
|
res.header("Access-Control-Allow-Headers", "Content-Type, Accept");
|
|
3353
3334
|
try {
|
|
3354
|
-
const routes =
|
|
3335
|
+
const routes = await fetchRoutesFromBackend();
|
|
3355
3336
|
const groups = groupRoutesByModule(routes);
|
|
3356
3337
|
res.json({
|
|
3357
3338
|
groups,
|
|
3358
3339
|
total: routes.length
|
|
3359
3340
|
});
|
|
3360
3341
|
} catch (error) {
|
|
3361
|
-
console.error("[api-list] Failed to
|
|
3342
|
+
console.error("[api-list] Failed to fetch routes:", error);
|
|
3362
3343
|
res.status(500).json({
|
|
3363
|
-
error: "Failed to
|
|
3344
|
+
error: "Failed to fetch routes",
|
|
3364
3345
|
message: error instanceof Error ? error.message : "Unknown error"
|
|
3365
3346
|
});
|
|
3366
3347
|
}
|
|
@@ -3599,7 +3580,7 @@ function capitalize2(str) {
|
|
|
3599
3580
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
3600
3581
|
}
|
|
3601
3582
|
__name(capitalize2, "capitalize");
|
|
3602
|
-
function
|
|
3583
|
+
function extractRoutes(app) {
|
|
3603
3584
|
const router = app._router;
|
|
3604
3585
|
if (!router?.stack) {
|
|
3605
3586
|
return [];
|
|
@@ -3645,7 +3626,7 @@ function extractRoutes2(app) {
|
|
|
3645
3626
|
router.stack.forEach((layer) => processLayer(layer));
|
|
3646
3627
|
return routes;
|
|
3647
3628
|
}
|
|
3648
|
-
__name(
|
|
3629
|
+
__name(extractRoutes, "extractRoutes");
|
|
3649
3630
|
function groupRoutesByModule2(routes) {
|
|
3650
3631
|
const groupMap = /* @__PURE__ */ new Map();
|
|
3651
3632
|
routes.forEach((route) => {
|
|
@@ -3674,7 +3655,7 @@ function createApiRoutesRouter() {
|
|
|
3674
3655
|
res.header("Access-Control-Allow-Methods", "GET, OPTIONS");
|
|
3675
3656
|
res.header("Access-Control-Allow-Headers", "Content-Type, Accept");
|
|
3676
3657
|
try {
|
|
3677
|
-
const routes =
|
|
3658
|
+
const routes = extractRoutes(req.app);
|
|
3678
3659
|
const groups = groupRoutesByModule2(routes);
|
|
3679
3660
|
res.json({
|
|
3680
3661
|
groups,
|
|
@@ -3744,11 +3725,8 @@ async function registerRouteMiddleware(server, middleware, context) {
|
|
|
3744
3725
|
console.error(`[Middleware] ${middleware.name}: Route middleware must have mountPath. Skipping.`);
|
|
3745
3726
|
return;
|
|
3746
3727
|
}
|
|
3747
|
-
console.log(`[Middleware] Creating router for: ${middleware.name}`);
|
|
3748
3728
|
const router = middleware.createRouter(context);
|
|
3749
|
-
console.log(`[Middleware] Router created for: ${middleware.name}, router stack length: ${router.stack?.length || "unknown"}`);
|
|
3750
3729
|
const fullMountPath = computeMountPath(context.basePath, middleware.mountPath);
|
|
3751
|
-
console.log(`[Middleware] Mounting ${middleware.name} at: ${fullMountPath}`);
|
|
3752
3730
|
server.use(fullMountPath, router);
|
|
3753
3731
|
logMiddlewareRegistration(middleware, fullMountPath);
|
|
3754
3732
|
}
|