@dangao/bun-server 1.8.1 → 1.8.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/controller/controller.d.ts.map +1 -1
- package/dist/core/application.d.ts.map +1 -1
- package/dist/error/handler.d.ts.map +1 -1
- package/dist/index.js +98 -21
- package/dist/middleware/builtin/error-handler.d.ts.map +1 -1
- package/dist/middleware/builtin/logger.d.ts.map +1 -1
- package/dist/router/decorators.d.ts +10 -10
- package/dist/router/decorators.d.ts.map +1 -1
- package/dist/router/router.d.ts.map +1 -1
- package/docs/api.md +194 -81
- package/docs/extensions.md +53 -0
- package/docs/guide.md +243 -1
- package/docs/microservice-config-center.md +73 -74
- package/docs/microservice-nacos.md +89 -90
- package/docs/microservice-service-registry.md +85 -86
- package/docs/microservice.md +142 -137
- package/docs/request-lifecycle.md +45 -4
- package/docs/symbol-interface-pattern.md +106 -106
- package/docs/zh/api.md +458 -18
- package/docs/zh/extensions.md +53 -0
- package/docs/zh/guide.md +251 -4
- package/docs/zh/microservice-config-center.md +258 -0
- package/docs/zh/microservice-nacos.md +346 -0
- package/docs/zh/microservice-service-registry.md +306 -0
- package/docs/zh/microservice.md +680 -0
- package/docs/zh/request-lifecycle.md +43 -5
- package/package.json +1 -1
- package/src/controller/controller.ts +10 -2
- package/src/core/application.ts +11 -0
- package/src/error/handler.ts +17 -0
- package/src/middleware/builtin/error-handler.ts +10 -0
- package/src/middleware/builtin/logger.ts +17 -0
- package/src/router/decorators.ts +15 -15
- package/src/router/router.ts +18 -1
- package/tests/controller/path-combination.test.ts +135 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/controller/controller.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/controller/controller.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAShD;;GAEG;AACH,eAAO,MAAM,uBAAuB,eAAuB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CAC9B;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,GAAE,MAAW,IACzB,QAAQ,WAAW,CAAC,OAAO,CAAC,UAI9C;AAED;;;GAGG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA4C;IACxE,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA8C;IAEnF,OAAO;IAIP;;OAEG;WACW,WAAW,IAAI,kBAAkB;IAO/C;;;OAGG;IACI,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI;IAgKnF;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,YAAY;IA+BpB;;;OAGG;IACI,YAAY,IAAI,SAAS;IAIhC;;;OAGG;IACI,iBAAiB,IAAI,WAAW,CAAC,OAAO,CAAC,EAAE;IAIlD;;;OAGG;IACI,wBAAwB,IAAI,WAAW,CAAC,OAAO,CAAC,EAAE;IAIzD;;OAEG;IACI,KAAK,IAAI,IAAI;CAKrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["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B;IAyBpC;;OAEG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAYlC;;;;;OAKG;IACU,gBAAgB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB9D;;OAEG;YACW,eAAe;IAkB7B;;;;OAIG;YACW,aAAa;IAyC3B;;;OAGG;IACI,kBAAkB,CAAC,eAAe,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI;IAKtE;;;OAGG;IACI,cAAc,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI;IAqBrD;;;OAGG;IACH,OAAO,CAAC,kCAAkC;IAc1C;;;OAGG;IACI,wBAAwB,CAAC,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI;IAIzE;;;OAGG;IACI,iBAAiB,CAAC,SAAS,EAAE,oBAAoB,GAAG,IAAI;IAK/D;;;OAGG;IACI,SAAS,IAAI,SAAS,GAAG,SAAS;IAIzC;;;OAGG;YACW,gBAAgB;IAsB9B;;;OAGG;YACW,kBAAkB;IAwBhC;;;OAGG;IACI,YAAY;IAInB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IA2B7B;;OAEG;IACH,OAAO,CAAC,oBAAoB;CAS7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/error/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/error/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAO/C;;GAEG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsErF"}
|
package/dist/index.js
CHANGED
|
@@ -331,6 +331,8 @@ class Route {
|
|
|
331
331
|
var init_route = () => {};
|
|
332
332
|
|
|
333
333
|
// src/router/router.ts
|
|
334
|
+
import { LoggerManager as LoggerManager3 } from "@dangao/logsmith";
|
|
335
|
+
|
|
334
336
|
class Router {
|
|
335
337
|
routes = [];
|
|
336
338
|
staticRoutes = new Map;
|
|
@@ -400,11 +402,20 @@ class Router {
|
|
|
400
402
|
async preHandle(context) {
|
|
401
403
|
const method = context.method;
|
|
402
404
|
const path = this.normalizePath(context.path);
|
|
405
|
+
const logger = LoggerManager3.getLogger();
|
|
403
406
|
const result = this.findRouteWithMatch(method, path);
|
|
404
407
|
if (!result) {
|
|
408
|
+
logger.debug("[Router] Route not matched", { method, path });
|
|
405
409
|
return;
|
|
406
410
|
}
|
|
407
411
|
const { route, match } = result;
|
|
412
|
+
logger.debug("[Router] Route matched", {
|
|
413
|
+
method,
|
|
414
|
+
path,
|
|
415
|
+
routePath: route.path,
|
|
416
|
+
controller: route.controllerClass?.name,
|
|
417
|
+
methodName: route.methodName
|
|
418
|
+
});
|
|
408
419
|
if (match.matched) {
|
|
409
420
|
context.params = match.params;
|
|
410
421
|
}
|
|
@@ -418,11 +429,17 @@ class Router {
|
|
|
418
429
|
async handle(context) {
|
|
419
430
|
const method = context.method;
|
|
420
431
|
const path = this.normalizePath(context.path);
|
|
432
|
+
const logger = LoggerManager3.getLogger();
|
|
421
433
|
const result = this.findRouteWithMatch(method, path);
|
|
422
434
|
if (!result) {
|
|
423
435
|
return;
|
|
424
436
|
}
|
|
425
437
|
const { route, match } = result;
|
|
438
|
+
logger.debug("[Router] Executing handler", {
|
|
439
|
+
path: route.path,
|
|
440
|
+
controller: route.controllerClass?.name,
|
|
441
|
+
methodName: route.methodName
|
|
442
|
+
});
|
|
426
443
|
if (match.matched) {
|
|
427
444
|
context.params = match.params;
|
|
428
445
|
}
|
|
@@ -503,7 +520,7 @@ var init_types = __esm(() => {
|
|
|
503
520
|
|
|
504
521
|
// src/di/container.ts
|
|
505
522
|
import"reflect-metadata";
|
|
506
|
-
import { LoggerManager as
|
|
523
|
+
import { LoggerManager as LoggerManager4 } from "@dangao/logsmith";
|
|
507
524
|
|
|
508
525
|
class Container {
|
|
509
526
|
parent;
|
|
@@ -621,7 +638,7 @@ class Container {
|
|
|
621
638
|
resolveInternal(token) {
|
|
622
639
|
const tokenType = typeof token;
|
|
623
640
|
const tokenString = String(token);
|
|
624
|
-
const logger =
|
|
641
|
+
const logger = LoggerManager4.getLogger();
|
|
625
642
|
if (tokenString.includes("Level2") || tokenString.includes("Dependency") || tokenString.includes("Service")) {
|
|
626
643
|
logger.debug(`[DI Debug] resolveInternal: token=${tokenString}, tokenType=${tokenType}`);
|
|
627
644
|
}
|
|
@@ -1121,7 +1138,7 @@ var init_param_binder = __esm(() => {
|
|
|
1121
1138
|
|
|
1122
1139
|
// src/router/decorators.ts
|
|
1123
1140
|
import"reflect-metadata";
|
|
1124
|
-
function createRouteDecorator(method, path) {
|
|
1141
|
+
function createRouteDecorator(method, path = "") {
|
|
1125
1142
|
return function(target, propertyKey, descriptor) {
|
|
1126
1143
|
const constructor = target.constructor;
|
|
1127
1144
|
if (constructor && typeof constructor === "function") {
|
|
@@ -1147,26 +1164,26 @@ function createRouteDecorator(method, path) {
|
|
|
1147
1164
|
}
|
|
1148
1165
|
existingRoutes.push({
|
|
1149
1166
|
method,
|
|
1150
|
-
path,
|
|
1167
|
+
path: path ?? "",
|
|
1151
1168
|
handler: descriptor.value,
|
|
1152
1169
|
propertyKey: propertyKeyStr || undefined
|
|
1153
1170
|
});
|
|
1154
1171
|
Reflect.defineMetadata(ROUTE_METADATA_KEY, existingRoutes, target);
|
|
1155
1172
|
};
|
|
1156
1173
|
}
|
|
1157
|
-
function GET(path) {
|
|
1174
|
+
function GET(path = "") {
|
|
1158
1175
|
return createRouteDecorator("GET", path);
|
|
1159
1176
|
}
|
|
1160
|
-
function POST(path) {
|
|
1177
|
+
function POST(path = "") {
|
|
1161
1178
|
return createRouteDecorator("POST", path);
|
|
1162
1179
|
}
|
|
1163
|
-
function PUT(path) {
|
|
1180
|
+
function PUT(path = "") {
|
|
1164
1181
|
return createRouteDecorator("PUT", path);
|
|
1165
1182
|
}
|
|
1166
|
-
function DELETE(path) {
|
|
1183
|
+
function DELETE(path = "") {
|
|
1167
1184
|
return createRouteDecorator("DELETE", path);
|
|
1168
1185
|
}
|
|
1169
|
-
function PATCH(path) {
|
|
1186
|
+
function PATCH(path = "") {
|
|
1170
1187
|
return createRouteDecorator("PATCH", path);
|
|
1171
1188
|
}
|
|
1172
1189
|
var ROUTE_METADATA_KEY;
|
|
@@ -1330,10 +1347,10 @@ var init_decorators4 = __esm(() => {
|
|
|
1330
1347
|
});
|
|
1331
1348
|
|
|
1332
1349
|
// src/middleware/builtin/logger.ts
|
|
1333
|
-
import { LoggerManager as
|
|
1350
|
+
import { LoggerManager as LoggerManager5 } from "@dangao/logsmith";
|
|
1334
1351
|
function createLoggerMiddleware(options = {}) {
|
|
1335
1352
|
const log = options.logger ?? ((message, details) => {
|
|
1336
|
-
const logger =
|
|
1353
|
+
const logger = LoggerManager5.getLogger();
|
|
1337
1354
|
if (details) {
|
|
1338
1355
|
logger.info(message, details);
|
|
1339
1356
|
} else {
|
|
@@ -1349,12 +1366,20 @@ function createLoggerMiddleware(options = {}) {
|
|
|
1349
1366
|
} finally {
|
|
1350
1367
|
const status = response?.status ?? context.statusCode ?? 200;
|
|
1351
1368
|
log(`${prefix} ${context.method} ${context.path} ${status}`);
|
|
1369
|
+
if (status >= 400) {
|
|
1370
|
+
const logger = LoggerManager5.getLogger();
|
|
1371
|
+
logger.debug(`${prefix} Error response`, {
|
|
1372
|
+
method: context.method,
|
|
1373
|
+
path: context.path,
|
|
1374
|
+
statusCode: status
|
|
1375
|
+
});
|
|
1376
|
+
}
|
|
1352
1377
|
}
|
|
1353
1378
|
};
|
|
1354
1379
|
}
|
|
1355
1380
|
function createRequestLoggingMiddleware(options = {}) {
|
|
1356
1381
|
const log = options.logger ?? ((message, details) => {
|
|
1357
|
-
const logger =
|
|
1382
|
+
const logger = LoggerManager5.getLogger();
|
|
1358
1383
|
logger.info(message, details);
|
|
1359
1384
|
});
|
|
1360
1385
|
const prefix = options.prefix ?? "[Request]";
|
|
@@ -1372,6 +1397,15 @@ function createRequestLoggingMiddleware(options = {}) {
|
|
|
1372
1397
|
} catch (error) {
|
|
1373
1398
|
const duration = performance.now() - start;
|
|
1374
1399
|
log(`${prefix} ${context.method} ${context.path} error ${duration.toFixed(2)}ms`, error instanceof Error ? { error: error.message } : undefined);
|
|
1400
|
+
if (error instanceof Error) {
|
|
1401
|
+
LoggerManager5.getLogger().debug(`${prefix} Request error details`, {
|
|
1402
|
+
method: context.method,
|
|
1403
|
+
path: context.path,
|
|
1404
|
+
durationMs: duration.toFixed(2),
|
|
1405
|
+
message: error.message,
|
|
1406
|
+
stack: error.stack
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1375
1409
|
throw error;
|
|
1376
1410
|
}
|
|
1377
1411
|
};
|
|
@@ -2449,6 +2483,7 @@ var exports_handler = {};
|
|
|
2449
2483
|
__export(exports_handler, {
|
|
2450
2484
|
handleError: () => handleError
|
|
2451
2485
|
});
|
|
2486
|
+
import { LoggerManager as LoggerManager6 } from "@dangao/logsmith";
|
|
2452
2487
|
async function handleError(error, context) {
|
|
2453
2488
|
const registry = ExceptionFilterRegistry.getInstance();
|
|
2454
2489
|
const filterResponse = await registry.execute(error, context);
|
|
@@ -2457,6 +2492,15 @@ async function handleError(error, context) {
|
|
|
2457
2492
|
}
|
|
2458
2493
|
if (error instanceof HttpException) {
|
|
2459
2494
|
context.setStatus(error.status);
|
|
2495
|
+
if (error.status >= 400) {
|
|
2496
|
+
LoggerManager6.getLogger().debug("HttpException", {
|
|
2497
|
+
method: context.method,
|
|
2498
|
+
path: context.path,
|
|
2499
|
+
status: error.status,
|
|
2500
|
+
code: error.code,
|
|
2501
|
+
message: error.message
|
|
2502
|
+
});
|
|
2503
|
+
}
|
|
2460
2504
|
let errorMessage = error.message;
|
|
2461
2505
|
if (error.code) {
|
|
2462
2506
|
const acceptLanguage = context.getHeader("accept-language");
|
|
@@ -2483,7 +2527,14 @@ async function handleError(error, context) {
|
|
|
2483
2527
|
});
|
|
2484
2528
|
}
|
|
2485
2529
|
const message = error instanceof Error ? error.message : String(error);
|
|
2530
|
+
const stack = error instanceof Error ? error.stack : undefined;
|
|
2486
2531
|
context.setStatus(500);
|
|
2532
|
+
LoggerManager6.getLogger().debug("Internal error (500)", {
|
|
2533
|
+
method: context.method,
|
|
2534
|
+
path: context.path,
|
|
2535
|
+
message,
|
|
2536
|
+
stack
|
|
2537
|
+
});
|
|
2487
2538
|
return context.createResponse({
|
|
2488
2539
|
error: "Internal Server Error",
|
|
2489
2540
|
details: message
|
|
@@ -2504,24 +2555,32 @@ var init_error = __esm(() => {
|
|
|
2504
2555
|
});
|
|
2505
2556
|
|
|
2506
2557
|
// src/middleware/builtin/error-handler.ts
|
|
2507
|
-
import { LoggerManager as
|
|
2558
|
+
import { LoggerManager as LoggerManager7 } from "@dangao/logsmith";
|
|
2508
2559
|
function createErrorHandlingMiddleware(options = {}) {
|
|
2509
2560
|
const log = options.logger ?? ((error, context) => {
|
|
2510
|
-
|
|
2561
|
+
LoggerManager7.getLogger().error("[Error]", { ...context, error });
|
|
2511
2562
|
});
|
|
2512
2563
|
const expose = options.exposeError ?? false;
|
|
2513
2564
|
const defaultStatus = options.statusCode ?? 500;
|
|
2514
2565
|
return async (context, next) => {
|
|
2515
|
-
const logger =
|
|
2566
|
+
const logger = LoggerManager7.getLogger();
|
|
2516
2567
|
try {
|
|
2517
2568
|
return await next();
|
|
2518
2569
|
} catch (error) {
|
|
2570
|
+
const routeHandler = context.routeHandler;
|
|
2519
2571
|
log(error, { method: context.method, path: context.path });
|
|
2520
2572
|
logger.error("Unhandled error", {
|
|
2521
2573
|
method: context.method,
|
|
2522
2574
|
path: context.path,
|
|
2523
2575
|
error
|
|
2524
2576
|
});
|
|
2577
|
+
logger.debug("Unhandled error details", {
|
|
2578
|
+
method: context.method,
|
|
2579
|
+
path: context.path,
|
|
2580
|
+
routeHandler: routeHandler ? `${routeHandler.controller?.name ?? "unknown"}.${routeHandler.method ?? "unknown"}` : undefined,
|
|
2581
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
2582
|
+
stack: error instanceof Error ? error.stack : undefined
|
|
2583
|
+
});
|
|
2525
2584
|
if (error instanceof Response) {
|
|
2526
2585
|
return error;
|
|
2527
2586
|
}
|
|
@@ -3028,7 +3087,7 @@ var init_permission_interceptor = __esm(() => {
|
|
|
3028
3087
|
|
|
3029
3088
|
// src/extensions/logger-extension.ts
|
|
3030
3089
|
import {
|
|
3031
|
-
LoggerManager as
|
|
3090
|
+
LoggerManager as LoggerManager8,
|
|
3032
3091
|
LogLevel,
|
|
3033
3092
|
SimpleLogger
|
|
3034
3093
|
} from "@dangao/logsmith";
|
|
@@ -3043,7 +3102,7 @@ class LoggerExtension {
|
|
|
3043
3102
|
}
|
|
3044
3103
|
register(container) {
|
|
3045
3104
|
const logger = new SimpleLogger(this.options);
|
|
3046
|
-
|
|
3105
|
+
LoggerManager8.setLogger(logger);
|
|
3047
3106
|
container.registerInstance(SimpleLogger, logger);
|
|
3048
3107
|
container.registerInstance(LOGGER_TOKEN, logger);
|
|
3049
3108
|
}
|
|
@@ -3113,7 +3172,7 @@ var init_logger_module = __esm(() => {
|
|
|
3113
3172
|
});
|
|
3114
3173
|
|
|
3115
3174
|
// src/extensions/index.ts
|
|
3116
|
-
import { LoggerManager as
|
|
3175
|
+
import { LoggerManager as LoggerManager9, LogLevel as LogLevel2, SimpleLogger as SimpleLogger2 } from "@dangao/logsmith";
|
|
3117
3176
|
var init_extensions = __esm(() => {
|
|
3118
3177
|
init_logger_extension();
|
|
3119
3178
|
init_logger_module();
|
|
@@ -3230,6 +3289,7 @@ __export(exports_controller, {
|
|
|
3230
3289
|
CONTROLLER_METADATA_KEY: () => CONTROLLER_METADATA_KEY
|
|
3231
3290
|
});
|
|
3232
3291
|
import"reflect-metadata";
|
|
3292
|
+
import { LoggerManager as LoggerManager10 } from "@dangao/logsmith";
|
|
3233
3293
|
function Controller(path = "") {
|
|
3234
3294
|
return function(target) {
|
|
3235
3295
|
Reflect.defineMetadata(CONTROLLER_METADATA_KEY, { path, target }, target);
|
|
@@ -3327,6 +3387,13 @@ class ControllerRegistry {
|
|
|
3327
3387
|
}
|
|
3328
3388
|
return context.createResponse(responseData);
|
|
3329
3389
|
} catch (error) {
|
|
3390
|
+
LoggerManager10.getLogger().debug("Controller handler error", {
|
|
3391
|
+
controller: controllerClass.name,
|
|
3392
|
+
method: propertyKey,
|
|
3393
|
+
path: context.path,
|
|
3394
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
3395
|
+
stack: error instanceof Error ? error.stack : undefined
|
|
3396
|
+
});
|
|
3330
3397
|
const { handleError: handleError2 } = await Promise.resolve().then(() => (init_handler(), exports_handler));
|
|
3331
3398
|
return await handleError2(error, context);
|
|
3332
3399
|
}
|
|
@@ -3343,7 +3410,7 @@ class ControllerRegistry {
|
|
|
3343
3410
|
if (!base) {
|
|
3344
3411
|
base = "/";
|
|
3345
3412
|
}
|
|
3346
|
-
const method = methodPath.replace(/^\/+/, "");
|
|
3413
|
+
const method = (methodPath ?? "").replace(/^\/+/, "");
|
|
3347
3414
|
if (!method) {
|
|
3348
3415
|
return base === "/" ? "/" : base;
|
|
3349
3416
|
}
|
|
@@ -5338,7 +5405,7 @@ CacheModule = __legacyDecorateClassTS([
|
|
|
5338
5405
|
})
|
|
5339
5406
|
], CacheModule);
|
|
5340
5407
|
// src/core/application.ts
|
|
5341
|
-
import { LoggerManager as
|
|
5408
|
+
import { LoggerManager as LoggerManager11 } from "@dangao/logsmith";
|
|
5342
5409
|
|
|
5343
5410
|
class Application {
|
|
5344
5411
|
server;
|
|
@@ -5433,6 +5500,12 @@ class Application {
|
|
|
5433
5500
|
}
|
|
5434
5501
|
}
|
|
5435
5502
|
async handleRequest(context) {
|
|
5503
|
+
const logger = LoggerManager11.getLogger();
|
|
5504
|
+
logger.debug("[Request] Incoming", {
|
|
5505
|
+
method: context.method,
|
|
5506
|
+
path: context.path,
|
|
5507
|
+
url: context.url?.href
|
|
5508
|
+
});
|
|
5436
5509
|
return await contextStore.run(context, async () => {
|
|
5437
5510
|
if (["POST", "PUT", "PATCH"].includes(context.method)) {
|
|
5438
5511
|
await context.getBody();
|
|
@@ -5445,6 +5518,10 @@ class Application {
|
|
|
5445
5518
|
if (response) {
|
|
5446
5519
|
return response;
|
|
5447
5520
|
}
|
|
5521
|
+
logger.debug("[Router] No route matched", {
|
|
5522
|
+
method: context.method,
|
|
5523
|
+
path: context.path
|
|
5524
|
+
});
|
|
5448
5525
|
context.setStatus(404);
|
|
5449
5526
|
return context.createResponse({ error: "Not Found" });
|
|
5450
5527
|
});
|
|
@@ -5524,7 +5601,7 @@ class Application {
|
|
|
5524
5601
|
if (this.signalHandlersInstalled) {
|
|
5525
5602
|
return;
|
|
5526
5603
|
}
|
|
5527
|
-
const logger =
|
|
5604
|
+
const logger = LoggerManager11.getLogger();
|
|
5528
5605
|
const shutdownHandler = async (signal) => {
|
|
5529
5606
|
logger.info(`Received ${signal}, starting graceful shutdown...`);
|
|
5530
5607
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../../src/middleware/builtin/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAOhD,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAE7E;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,GAAE,mBAAwB,GAChC,UAAU,
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../../src/middleware/builtin/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAOhD,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAE7E;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,GAAE,mBAAwB,GAChC,UAAU,CAsEZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/middleware/builtin/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAEtE;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,GAAE,uBAA4B,GACpC,UAAU,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/middleware/builtin/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAEtE;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,GAAE,uBAA4B,GACpC,UAAU,CA8BZ;AAED,MAAM,WAAW,qBAAsB,SAAQ,uBAAuB;IACpE;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,GAAE,qBAA0B,GAClC,UAAU,CA2CZ"}
|
|
@@ -19,27 +19,27 @@ export interface RouteMetadata {
|
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* GET 路由装饰器
|
|
22
|
-
* @param path -
|
|
22
|
+
* @param path - 路由路径(可选,默认 '',即 @GET() 映射到控制器基础路径或 /)
|
|
23
23
|
*/
|
|
24
|
-
export declare function GET(path
|
|
24
|
+
export declare function GET(path?: string): (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
25
25
|
/**
|
|
26
26
|
* POST 路由装饰器
|
|
27
|
-
* @param path -
|
|
27
|
+
* @param path - 路由路径(可选,默认 '')
|
|
28
28
|
*/
|
|
29
|
-
export declare function POST(path
|
|
29
|
+
export declare function POST(path?: string): (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
30
30
|
/**
|
|
31
31
|
* PUT 路由装饰器
|
|
32
|
-
* @param path -
|
|
32
|
+
* @param path - 路由路径(可选,默认 '')
|
|
33
33
|
*/
|
|
34
|
-
export declare function PUT(path
|
|
34
|
+
export declare function PUT(path?: string): (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
35
35
|
/**
|
|
36
36
|
* DELETE 路由装饰器
|
|
37
|
-
* @param path -
|
|
37
|
+
* @param path - 路由路径(可选,默认 '')
|
|
38
38
|
*/
|
|
39
|
-
export declare function DELETE(path
|
|
39
|
+
export declare function DELETE(path?: string): (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
40
40
|
/**
|
|
41
41
|
* PATCH 路由装饰器
|
|
42
|
-
* @param path -
|
|
42
|
+
* @param path - 路由路径(可选,默认 '')
|
|
43
43
|
*/
|
|
44
|
-
export declare function PATCH(path
|
|
44
|
+
export declare function PATCH(path?: string): (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
45
45
|
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/router/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C;;GAEG;AACH,eAAO,MAAM,kBAAkB,eAAkB,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,YAAY,CAAC;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA8DD;;;GAGG;AACH,wBAAgB,GAAG,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/router/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C;;GAEG;AACH,eAAO,MAAM,kBAAkB,eAAkB,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,YAAY,CAAC;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA8DD;;;GAGG;AACH,wBAAgB,GAAG,CAAC,IAAI,GAAE,MAAW,YAzDV,GAAG,eAAe,MAAM,GAAG,MAAM,cAAc,kBAAkB,UA2D3F;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,IAAI,GAAE,MAAW,YAjEX,GAAG,eAAe,MAAM,GAAG,MAAM,cAAc,kBAAkB,UAmE3F;AAED;;;GAGG;AACH,wBAAgB,GAAG,CAAC,IAAI,GAAE,MAAW,YAzEV,GAAG,eAAe,MAAM,GAAG,MAAM,cAAc,kBAAkB,UA2E3F;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,GAAE,MAAW,YAjFb,GAAG,eAAe,MAAM,GAAG,MAAM,cAAc,kBAAkB,UAmF3F;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,GAAE,MAAW,YAzFZ,GAAG,eAAe,MAAM,GAAG,MAAM,cAAc,kBAAkB,UA2F3F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/router/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/router/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,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