@spinajs/http 2.0.474 → 2.0.476

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.
Files changed (103) hide show
  1. package/lib/cjs/cache.d.ts +9 -10
  2. package/lib/cjs/cache.d.ts.map +1 -1
  3. package/lib/cjs/cache.js +41 -86
  4. package/lib/cjs/cache.js.map +1 -1
  5. package/lib/cjs/controllers.d.ts +3 -33
  6. package/lib/cjs/controllers.d.ts.map +1 -1
  7. package/lib/cjs/controllers.js +70 -97
  8. package/lib/cjs/controllers.js.map +1 -1
  9. package/lib/cjs/decorators.d.ts.map +1 -1
  10. package/lib/cjs/decorators.js +0 -55
  11. package/lib/cjs/decorators.js.map +1 -1
  12. package/lib/cjs/index.d.ts +0 -7
  13. package/lib/cjs/index.d.ts.map +1 -1
  14. package/lib/cjs/index.js +0 -7
  15. package/lib/cjs/index.js.map +1 -1
  16. package/lib/cjs/interfaces.d.ts +1 -27
  17. package/lib/cjs/interfaces.d.ts.map +1 -1
  18. package/lib/cjs/interfaces.js.map +1 -1
  19. package/lib/cjs/server.d.ts +0 -7
  20. package/lib/cjs/server.d.ts.map +1 -1
  21. package/lib/cjs/server.js +24 -9
  22. package/lib/cjs/server.js.map +1 -1
  23. package/lib/mjs/cache.d.ts +9 -10
  24. package/lib/mjs/cache.d.ts.map +1 -1
  25. package/lib/mjs/cache.js +41 -86
  26. package/lib/mjs/cache.js.map +1 -1
  27. package/lib/mjs/controllers.d.ts +3 -33
  28. package/lib/mjs/controllers.d.ts.map +1 -1
  29. package/lib/mjs/controllers.js +39 -99
  30. package/lib/mjs/controllers.js.map +1 -1
  31. package/lib/mjs/decorators.d.ts.map +1 -1
  32. package/lib/mjs/decorators.js +0 -55
  33. package/lib/mjs/decorators.js.map +1 -1
  34. package/lib/mjs/index.d.ts +0 -7
  35. package/lib/mjs/index.d.ts.map +1 -1
  36. package/lib/mjs/index.js +0 -7
  37. package/lib/mjs/index.js.map +1 -1
  38. package/lib/mjs/interfaces.d.ts +1 -27
  39. package/lib/mjs/interfaces.d.ts.map +1 -1
  40. package/lib/mjs/interfaces.js.map +1 -1
  41. package/lib/mjs/server.d.ts +0 -7
  42. package/lib/mjs/server.d.ts.map +1 -1
  43. package/lib/mjs/server.js +24 -9
  44. package/lib/mjs/server.js.map +1 -1
  45. package/lib/tsconfig.cjs.tsbuildinfo +1 -1
  46. package/lib/tsconfig.mjs.tsbuildinfo +1 -1
  47. package/package.json +11 -11
  48. package/lib/cjs/middlewares/AccessLog.d.ts +0 -23
  49. package/lib/cjs/middlewares/AccessLog.d.ts.map +0 -1
  50. package/lib/cjs/middlewares/AccessLog.js +0 -73
  51. package/lib/cjs/middlewares/AccessLog.js.map +0 -1
  52. package/lib/cjs/middlewares/Compression.d.ts +0 -21
  53. package/lib/cjs/middlewares/Compression.d.ts.map +0 -1
  54. package/lib/cjs/middlewares/Compression.js +0 -62
  55. package/lib/cjs/middlewares/Compression.js.map +0 -1
  56. package/lib/cjs/middlewares/Cors.d.ts +0 -25
  57. package/lib/cjs/middlewares/Cors.d.ts.map +0 -1
  58. package/lib/cjs/middlewares/Cors.js +0 -81
  59. package/lib/cjs/middlewares/Cors.js.map +0 -1
  60. package/lib/cjs/middlewares/ErrorHandler.d.ts +0 -17
  61. package/lib/cjs/middlewares/ErrorHandler.d.ts.map +0 -1
  62. package/lib/cjs/middlewares/ErrorHandler.js +0 -42
  63. package/lib/cjs/middlewares/ErrorHandler.js.map +0 -1
  64. package/lib/cjs/middlewares/NotFound.d.ts +0 -18
  65. package/lib/cjs/middlewares/NotFound.d.ts.map +0 -1
  66. package/lib/cjs/middlewares/NotFound.js +0 -48
  67. package/lib/cjs/middlewares/NotFound.js.map +0 -1
  68. package/lib/cjs/middlewares/ServerTiming.d.ts +0 -25
  69. package/lib/cjs/middlewares/ServerTiming.d.ts.map +0 -1
  70. package/lib/cjs/middlewares/ServerTiming.js +0 -78
  71. package/lib/cjs/middlewares/ServerTiming.js.map +0 -1
  72. package/lib/cjs/middlewares/SlowRequestWarning.d.ts +0 -20
  73. package/lib/cjs/middlewares/SlowRequestWarning.d.ts.map +0 -1
  74. package/lib/cjs/middlewares/SlowRequestWarning.js +0 -74
  75. package/lib/cjs/middlewares/SlowRequestWarning.js.map +0 -1
  76. package/lib/mjs/middlewares/AccessLog.d.ts +0 -23
  77. package/lib/mjs/middlewares/AccessLog.d.ts.map +0 -1
  78. package/lib/mjs/middlewares/AccessLog.js +0 -70
  79. package/lib/mjs/middlewares/AccessLog.js.map +0 -1
  80. package/lib/mjs/middlewares/Compression.d.ts +0 -21
  81. package/lib/mjs/middlewares/Compression.d.ts.map +0 -1
  82. package/lib/mjs/middlewares/Compression.js +0 -56
  83. package/lib/mjs/middlewares/Compression.js.map +0 -1
  84. package/lib/mjs/middlewares/Cors.d.ts +0 -25
  85. package/lib/mjs/middlewares/Cors.d.ts.map +0 -1
  86. package/lib/mjs/middlewares/Cors.js +0 -75
  87. package/lib/mjs/middlewares/Cors.js.map +0 -1
  88. package/lib/mjs/middlewares/ErrorHandler.d.ts +0 -17
  89. package/lib/mjs/middlewares/ErrorHandler.d.ts.map +0 -1
  90. package/lib/mjs/middlewares/ErrorHandler.js +0 -39
  91. package/lib/mjs/middlewares/ErrorHandler.js.map +0 -1
  92. package/lib/mjs/middlewares/NotFound.d.ts +0 -18
  93. package/lib/mjs/middlewares/NotFound.d.ts.map +0 -1
  94. package/lib/mjs/middlewares/NotFound.js +0 -45
  95. package/lib/mjs/middlewares/NotFound.js.map +0 -1
  96. package/lib/mjs/middlewares/ServerTiming.d.ts +0 -25
  97. package/lib/mjs/middlewares/ServerTiming.d.ts.map +0 -1
  98. package/lib/mjs/middlewares/ServerTiming.js +0 -75
  99. package/lib/mjs/middlewares/ServerTiming.js.map +0 -1
  100. package/lib/mjs/middlewares/SlowRequestWarning.d.ts +0 -20
  101. package/lib/mjs/middlewares/SlowRequestWarning.d.ts.map +0 -1
  102. package/lib/mjs/middlewares/SlowRequestWarning.js +0 -71
  103. package/lib/mjs/middlewares/SlowRequestWarning.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spinajs/http",
3
- "version": "2.0.474",
3
+ "version": "2.0.476",
4
4
  "description": "framework HTTP module base on express.js",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -62,16 +62,16 @@
62
62
  "cpx": "1.5.0"
63
63
  },
64
64
  "dependencies": {
65
- "@spinajs/configuration": "^2.0.474",
66
- "@spinajs/di": "^2.0.474",
67
- "@spinajs/exceptions": "^2.0.474",
68
- "@spinajs/fs": "^2.0.474",
69
- "@spinajs/log": "^2.0.474",
70
- "@spinajs/reflection": "^2.0.474",
71
- "@spinajs/templates": "^2.0.474",
72
- "@spinajs/validation": "^2.0.474",
73
- "@spinajs/templates-pug": "^2.0.474",
74
- "@spinajs/util": "^2.0.474",
65
+ "@spinajs/configuration": "^2.0.476",
66
+ "@spinajs/di": "^2.0.476",
67
+ "@spinajs/exceptions": "^2.0.476",
68
+ "@spinajs/fs": "^2.0.476",
69
+ "@spinajs/log": "^2.0.476",
70
+ "@spinajs/reflection": "^2.0.476",
71
+ "@spinajs/templates": "^2.0.476",
72
+ "@spinajs/validation": "^2.0.476",
73
+ "@spinajs/templates-pug": "^2.0.476",
74
+ "@spinajs/util": "^2.0.476",
75
75
  "compression": "^1.7.4",
76
76
  "cookie-parser": "^1.4.6",
77
77
  "cookie-signature": "^1.2.0",
@@ -1,23 +0,0 @@
1
- import * as express from 'express';
2
- import { Log } from '@spinajs/log';
3
- import { ServerMiddleware, Request as sRequest } from '../interfaces.js';
4
- /**
5
- * Emits one structured log line per HTTP request.
6
- *
7
- * Pairs with RequestId / RealIp / ResponseTime: the line includes
8
- * `requestId`, `ip`, and `ms` populated by those middlewares. The log is
9
- * emitted on the response's `finish` event so it captures the final status
10
- * code and reflects the actual time spent.
11
- *
12
- * Config:
13
- * http.accessLog.enabled (default true)
14
- * http.accessLog.logger (default 'http.access')
15
- */
16
- export declare class AccessLog extends ServerMiddleware {
17
- protected Enabled: boolean;
18
- protected Log: Log;
19
- constructor();
20
- before(): ((req: sRequest, res: express.Response, next: express.NextFunction) => void) | null;
21
- after(): null;
22
- }
23
- //# sourceMappingURL=AccessLog.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AccessLog.d.ts","sourceRoot":"","sources":["../../../src/middlewares/AccessLog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,OAAO,EAAU,GAAG,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEzE;;;;;;;;;;;GAWG;AACH,qBACa,SAAU,SAAQ,gBAAgB;IAE7C,SAAS,CAAC,OAAO,EAAG,OAAO,CAAC;IAG5B,SAAS,CAAC,GAAG,EAAG,GAAG,CAAC;;IASb,MAAM,IAAI,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,YAAY,KAAK,IAAI,CAAC,GAAG,IAAI;IAoB7F,KAAK,IAAI,IAAI;CAGrB"}
@@ -1,73 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.AccessLog = void 0;
13
- const di_1 = require("@spinajs/di");
14
- const configuration_1 = require("@spinajs/configuration");
15
- const log_1 = require("@spinajs/log");
16
- const interfaces_js_1 = require("../interfaces.js");
17
- /**
18
- * Emits one structured log line per HTTP request.
19
- *
20
- * Pairs with RequestId / RealIp / ResponseTime: the line includes
21
- * `requestId`, `ip`, and `ms` populated by those middlewares. The log is
22
- * emitted on the response's `finish` event so it captures the final status
23
- * code and reflects the actual time spent.
24
- *
25
- * Config:
26
- * http.accessLog.enabled (default true)
27
- * http.accessLog.logger (default 'http.access')
28
- */
29
- let AccessLog = class AccessLog extends interfaces_js_1.ServerMiddleware {
30
- constructor() {
31
- super();
32
- // Needs req.storage to exist (ReqStorage = -2), so any Order > -2 is fine.
33
- // Sit alongside RealIp / RequestId.
34
- this.Order = 2;
35
- }
36
- before() {
37
- if (!this.Enabled)
38
- return null;
39
- const log = this.Log;
40
- return (req, res, next) => {
41
- const startedAt = Date.now();
42
- res.on('finish', () => {
43
- log.info(`${req.method} ${req.originalUrl} ${res.statusCode} ${Date.now() - startedAt}ms`, {
44
- method: req.method,
45
- path: req.originalUrl,
46
- status: res.statusCode,
47
- ms: Date.now() - startedAt,
48
- ip: req.storage?.realIp,
49
- requestId: req.storage?.requestId,
50
- userAgent: req.headers['user-agent'],
51
- });
52
- });
53
- next();
54
- };
55
- }
56
- after() {
57
- return null;
58
- }
59
- };
60
- exports.AccessLog = AccessLog;
61
- __decorate([
62
- (0, configuration_1.Config)('http.accessLog.enabled', { defaultValue: true }),
63
- __metadata("design:type", Boolean)
64
- ], AccessLog.prototype, "Enabled", void 0);
65
- __decorate([
66
- (0, log_1.Logger)('http.access'),
67
- __metadata("design:type", log_1.Log)
68
- ], AccessLog.prototype, "Log", void 0);
69
- exports.AccessLog = AccessLog = __decorate([
70
- (0, di_1.Injectable)(interfaces_js_1.ServerMiddleware),
71
- __metadata("design:paramtypes", [])
72
- ], AccessLog);
73
- //# s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ACJ,CAAC;IAEM,KAAK;QACV,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AArCY,8BAAS;AAEV;IADT,IAAA,sBAAM,EAAC,wBAAwB,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;;0CAC7B;AAGlB;IADT,IAAA,YAAM,EAAC,aAAa,CAAC;8BACN,SAAG;sCAAC;oBALT,SAAS;IADrB,IAAA,eAAU,EAAC,gCAAgB,CAAC;;GAChB,SAAS,CAqCrB"}
@@ -1,21 +0,0 @@
1
- import * as express from 'express';
2
- import { ServerMiddleware, Request as sRequest } from '../interfaces.js';
3
- /**
4
- * Gzip/brotli compression of response bodies via the `compression` npm
5
- * package, wrapped as a ServerMiddleware so it plugs into the standard
6
- * lifecycle rather than being wired manually in `http.middlewares` config.
7
- *
8
- * Config:
9
- * http.compression.enabled (default true)
10
- * http.compression.threshold (default 1024, bytes — bodies below skipped)
11
- * http.compression.level (default -1, zlib default)
12
- */
13
- export declare class Compression extends ServerMiddleware {
14
- protected Enabled: boolean;
15
- protected Threshold: number;
16
- protected Level: number;
17
- constructor();
18
- before(): ((req: sRequest, res: express.Response, next: express.NextFunction) => void) | null;
19
- after(): null;
20
- }
21
- //# sourceMappingURL=Compression.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Compression.d.ts","sourceRoot":"","sources":["../../../src/middlewares/Compression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAKnC,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEzE;;;;;;;;;GASG;AACH,qBACa,WAAY,SAAQ,gBAAgB;IAE/C,SAAS,CAAC,OAAO,EAAG,OAAO,CAAC;IAG5B,SAAS,CAAC,SAAS,EAAG,MAAM,CAAC;IAG7B,SAAS,CAAC,KAAK,EAAG,MAAM,CAAC;;IAQlB,MAAM,IAAI,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,YAAY,KAAK,IAAI,CAAC,GAAG,IAAI;IAK7F,KAAK,IAAI,IAAI;CAGrB"}
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Compression = void 0;
16
- const di_1 = require("@spinajs/di");
17
- const configuration_1 = require("@spinajs/configuration");
18
- const compression_1 = __importDefault(require("compression"));
19
- const interfaces_js_1 = require("../interfaces.js");
20
- /**
21
- * Gzip/brotli compression of response bodies via the `compression` npm
22
- * package, wrapped as a ServerMiddleware so it plugs into the standard
23
- * lifecycle rather than being wired manually in `http.middlewares` config.
24
- *
25
- * Config:
26
- * http.compression.enabled (default true)
27
- * http.compression.threshold (default 1024, bytes — bodies below skipped)
28
- * http.compression.level (default -1, zlib default)
29
- */
30
- let Compression = class Compression extends interfaces_js_1.ServerMiddleware {
31
- constructor() {
32
- super();
33
- // Run early so the response stream is wrapped before controllers write.
34
- this.Order = 0;
35
- }
36
- before() {
37
- if (!this.Enabled)
38
- return null;
39
- return (0, compression_1.default)({ threshold: this.Threshold, level: this.Level });
40
- }
41
- after() {
42
- return null;
43
- }
44
- };
45
- exports.Compression = Compression;
46
- __decorate([
47
- (0, configuration_1.Config)('http.compression.enabled', { defaultValue: true }),
48
- __metadata("design:type", Boolean)
49
- ], Compression.prototype, "Enabled", void 0);
50
- __decorate([
51
- (0, configuration_1.Config)('http.compression.threshold', { defaultValue: 1024 }),
52
- __metadata("design:type", Number)
53
- ], Compression.prototype, "Threshold", void 0);
54
- __decorate([
55
- (0, configuration_1.Config)('http.compression.level', { defaultValue: -1 }),
56
- __metadata("design:type", Number)
57
- ], Compression.prototype, "Level", void 0);
58
- exports.Compression = Compression = __decorate([
59
- (0, di_1.Injectable)(interfaces_js_1.ServerMiddleware),
60
- __metadata("design:paramtypes", [])
61
- ], Compression);
62
- //# sourceMappingURL=Compression.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Compression.js","sourceRoot":"","sources":["../../../src/middlewares/Compression.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,oCAAyC;AACzC,0DAAgD;AAChD,8DAAsC;AAEtC,oDAAyE;AAEzE;;;;;;;;;GASG;AAEI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,gCAAgB;IAU/C;QACE,KAAK,EAAE,CAAC;QACR,wEAAwE;QACxE,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;IACjB,CAAC;IAEM,MAAM;QACX,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QAC/B,OAAO,IAAA,qBAAW,EAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAQ,CAAC;IAC9E,CAAC;IAEM,KAAK;QACV,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAxBY,kCAAW;AAEZ;IADT,IAAA,sBAAM,EAAC,0BAA0B,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;;4CAC/B;AAGlB;IADT,IAAA,sBAAM,EAAC,4BAA4B,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;;8CAChC;AAGnB;IADT,IAAA,sBAAM,EAAC,wBAAwB,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC;;0CAC9B;sBARd,WAAW;IADvB,IAAA,eAAU,EAAC,gCAAgB,CAAC;;GAChB,WAAW,CAwBvB"}
@@ -1,25 +0,0 @@
1
- import * as express from 'express';
2
- import { IContainer } from '@spinajs/di';
3
- import { Configuration } from '@spinajs/configuration';
4
- import { Log } from '@spinajs/log';
5
- import { ServerMiddleware, Request as sRequest } from '../interfaces.js';
6
- /**
7
- * CORS middleware extracted verbatim from the previous inline block in
8
- * `HttpServer.resolve()`. Behavior unchanged — same `http.cors` config keys,
9
- * same warning when missing, same origin matching. Lives here so it can be
10
- * tested, replaced, or disabled like any other ServerMiddleware.
11
- *
12
- * Config:
13
- * http.cors.origins (string[]; empty/missing allows all)
14
- * http.cors.exposedHeaders (string[])
15
- * http.cors.allowedHeaders (string[])
16
- */
17
- export declare class CorsMiddleware extends ServerMiddleware {
18
- protected Container: IContainer;
19
- protected Configuration: Configuration;
20
- protected Log: Log;
21
- constructor();
22
- before(): ((req: sRequest, res: express.Response, next: express.NextFunction) => void) | null;
23
- after(): null;
24
- }
25
- //# sourceMappingURL=Cors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Cors.d.ts","sourceRoot":"","sources":["../../../src/middlewares/Cors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAyB,UAAU,EAAc,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAU,GAAG,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,qBACa,cAAe,SAAQ,gBAAgB;IAElD,SAAS,CAAC,SAAS,EAAG,UAAU,CAAC;IAGjC,SAAS,CAAC,aAAa,EAAG,aAAa,CAAC;IAGxC,SAAS,CAAC,GAAG,EAAG,GAAG,CAAC;;IASb,MAAM,IAAI,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,YAAY,KAAK,IAAI,CAAC,GAAG,IAAI;IAuB7F,KAAK,IAAI,IAAI;CAGrB"}
@@ -1,81 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.CorsMiddleware = void 0;
16
- const cors_1 = __importDefault(require("cors"));
17
- const di_1 = require("@spinajs/di");
18
- const configuration_1 = require("@spinajs/configuration");
19
- const log_1 = require("@spinajs/log");
20
- const interfaces_js_1 = require("../interfaces.js");
21
- /**
22
- * CORS middleware extracted verbatim from the previous inline block in
23
- * `HttpServer.resolve()`. Behavior unchanged — same `http.cors` config keys,
24
- * same warning when missing, same origin matching. Lives here so it can be
25
- * tested, replaced, or disabled like any other ServerMiddleware.
26
- *
27
- * Config:
28
- * http.cors.origins (string[]; empty/missing allows all)
29
- * http.cors.exposedHeaders (string[])
30
- * http.cors.allowedHeaders (string[])
31
- */
32
- let CorsMiddleware = class CorsMiddleware extends interfaces_js_1.ServerMiddleware {
33
- constructor() {
34
- super();
35
- // Must run early — preflight needs to short-circuit before any business
36
- // middleware. Sit just after RequestStorage (-2) and ResponseTime (-1).
37
- this.Order = -1;
38
- }
39
- before() {
40
- const cOptions = this.Configuration.get('http.cors', undefined);
41
- if (!cOptions) {
42
- this.Log.warn(`CORS options not set, server may be unavaible from outside ! Please set http.cors configuration option.`);
43
- return null;
44
- }
45
- const corsOptions = {
46
- origin(origin, callback) {
47
- if (!cOptions || cOptions.origins.length === 0 || cOptions.origins.indexOf(origin) !== -1) {
48
- callback(null, true);
49
- }
50
- else {
51
- callback(new Error('cors not allowed'));
52
- }
53
- },
54
- exposedHeaders: cOptions.exposedHeaders,
55
- allowedHeaders: cOptions.allowedHeaders,
56
- credentials: true,
57
- };
58
- return (0, cors_1.default)(corsOptions);
59
- }
60
- after() {
61
- return null;
62
- }
63
- };
64
- exports.CorsMiddleware = CorsMiddleware;
65
- __decorate([
66
- (0, di_1.Autoinject)(di_1.Container),
67
- __metadata("design:type", Object)
68
- ], CorsMiddleware.prototype, "Container", void 0);
69
- __decorate([
70
- (0, di_1.Autoinject)(configuration_1.Configuration),
71
- __metadata("design:type", configuration_1.Configuration)
72
- ], CorsMiddleware.prototype, "Configuration", void 0);
73
- __decorate([
74
- (0, log_1.Logger)('http'),
75
- __metadata("design:type", log_1.Log)
76
- ], CorsMiddleware.prototype, "Log", void 0);
77
- exports.CorsMiddleware = CorsMiddleware = __decorate([
78
- (0, di_1.Injectable)(interfaces_js_1.ServerMiddleware),
79
- __metadata("design:paramtypes", [])
80
- ], CorsMiddleware);
81
- //# sourceMappingURL=Cors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Cors.js","sourceRoot":"","sources":["../../../src/middlewares/Cors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,gDAAwB;AACxB,oCAA4E;AAC5E,0D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EAAC,MAAM,CAAC;8BACC,SAAG;2CAAC;yBART,cAAc;IAD1B,IAAA,eAAU,EAAC,gCAAgB,CAAC;;GAChB,cAAc,CA2C1B"}
@@ -1,17 +0,0 @@
1
- import * as express from 'express';
2
- import { ServerMiddleware } from '../interfaces.js';
3
- /**
4
- * Last-resort error handler. Wraps the existing `__handle_error__` factory
5
- * (which produces a 4-arg Express error middleware that maps errors to
6
- * configured HTTP responses) into the standard ServerMiddleware lifecycle.
7
- *
8
- * Order MIN_SAFE_INTEGER places it at the very tail of the Express stack
9
- * after `HttpServer.start()` reverses by Order — exactly where Express
10
- * expects error middleware to live.
11
- */
12
- export declare class ErrorHandlerMiddleware extends ServerMiddleware {
13
- constructor();
14
- before(): null;
15
- after(): express.ErrorRequestHandler;
16
- }
17
- //# sourceMappingURL=ErrorHandler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ErrorHandler.d.ts","sourceRoot":"","sources":["../../../src/middlewares/ErrorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGpD;;;;;;;;GAQG;AACH,qBACa,sBAAuB,SAAQ,gBAAgB;;IAMnD,MAAM,IAAI,IAAI;IAId,KAAK,IAAI,OAAO,CAAC,mBAAmB;CAG5C"}
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ErrorHandlerMiddleware = void 0;
13
- const di_1 = require("@spinajs/di");
14
- const interfaces_js_1 = require("../interfaces.js");
15
- const error_js_1 = require("../error.js");
16
- /**
17
- * Last-resort error handler. Wraps the existing `__handle_error__` factory
18
- * (which produces a 4-arg Express error middleware that maps errors to
19
- * configured HTTP responses) into the standard ServerMiddleware lifecycle.
20
- *
21
- * Order MIN_SAFE_INTEGER places it at the very tail of the Express stack
22
- * after `HttpServer.start()` reverses by Order — exactly where Express
23
- * expects error middleware to live.
24
- */
25
- let ErrorHandlerMiddleware = class ErrorHandlerMiddleware extends interfaces_js_1.ServerMiddleware {
26
- constructor() {
27
- super();
28
- this.Order = Number.MIN_SAFE_INTEGER - 1;
29
- }
30
- before() {
31
- return null;
32
- }
33
- after() {
34
- return (0, error_js_1.__handle_error__)();
35
- }
36
- };
37
- exports.ErrorHandlerMiddleware = ErrorHandlerMiddleware;
38
- exports.ErrorHandlerMiddleware = ErrorHandlerMiddleware = __decorate([
39
- (0, di_1.Injectable)(interfaces_js_1.ServerMiddleware),
40
- __metadata("design:paramtypes", [])
41
- ], ErrorHandlerMiddleware);
42
- //# sourceMappingURL=ErrorHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ErrorHandler.js","sourceRoot":"","sources":["../../../src/middlewares/ErrorHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAAyC;AAEzC,oDAAoD;AACpD,0CAA+C;AAE/C;;;;;;;;GAQG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,gCAAgB;IAC1D;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,gBAAgB,GAAG,CAAC,CAAC;IAC3C,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK;QACV,OAAO,IAAA,2BAAgB,GAAE,CAAC;IAC5B,CAAC;CACF,CAAA;AAbY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,eAAU,EAAC,gCAAgB,CAAC;;GAChB,sBAAsB,CAalC"}
@@ -1,18 +0,0 @@
1
- import * as express from 'express';
2
- import { ServerMiddleware } from '../interfaces.js';
3
- /**
4
- * Catches requests that no controller route matched and turns them into a
5
- * standard ResourceNotFound error so {@link ErrorHandlerMiddleware} can
6
- * produce a proper HTTP response.
7
- *
8
- * Registered as a normal ServerMiddleware so it participates in the
9
- * established lifecycle (HttpServer.start() reverses by Order and applies
10
- * after()). Its Order is one step above MIN_SAFE_INTEGER so it lands at the
11
- * Express stack tail, just before the error handler.
12
- */
13
- export declare class NotFoundMiddleware extends ServerMiddleware {
14
- constructor();
15
- before(): null;
16
- after(): (req: express.Request, res: express.Response, next: express.NextFunction) => void;
17
- }
18
- //# sourceMappingURL=NotFound.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NotFound.d.ts","sourceRoot":"","sources":["../../../src/middlewares/NotFound.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;;;;GASG;AACH,qBACa,kBAAmB,SAAQ,gBAAgB;;IAS/C,MAAM,IAAI,IAAI;IAId,KAAK,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,YAAY,KAAK,IAAI;CAKlG"}
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.NotFoundMiddleware = void 0;
13
- const di_1 = require("@spinajs/di");
14
- const exceptions_1 = require("@spinajs/exceptions");
15
- const interfaces_js_1 = require("../interfaces.js");
16
- /**
17
- * Catches requests that no controller route matched and turns them into a
18
- * standard ResourceNotFound error so {@link ErrorHandlerMiddleware} can
19
- * produce a proper HTTP response.
20
- *
21
- * Registered as a normal ServerMiddleware so it participates in the
22
- * established lifecycle (HttpServer.start() reverses by Order and applies
23
- * after()). Its Order is one step above MIN_SAFE_INTEGER so it lands at the
24
- * Express stack tail, just before the error handler.
25
- */
26
- let NotFoundMiddleware = class NotFoundMiddleware extends interfaces_js_1.ServerMiddleware {
27
- constructor() {
28
- super();
29
- // Reverse-iteration over after() means lowest Order runs LAST and ends up
30
- // at the Express stack tail. We want NotFound right before ErrorHandler
31
- // (which uses MIN_SAFE_INTEGER), so we sit one step above.
32
- this.Order = Number.MIN_SAFE_INTEGER;
33
- }
34
- before() {
35
- return null;
36
- }
37
- after() {
38
- return (req, _res, next) => {
39
- next(new exceptions_1.ResourceNotFound(`Route not found: ${req.method} ${req.originalUrl}`));
40
- };
41
- }
42
- };
43
- exports.NotFoundMiddleware = NotFoundMiddleware;
44
- exports.NotFoundMiddleware = NotFoundMiddleware = __decorate([
45
- (0, di_1.Injectable)(interfaces_js_1.ServerMiddleware),
46
- __metadata("design:paramtypes", [])
47
- ], NotFoundMiddleware);
48
- //# sourceMappingURL=NotFound.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NotFound.js","sourceRoot":"","sources":["../../../src/middlewares/NotFound.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAAyC;AACzC,oDAAuD;AAEvD,oDAAoD;AAEpD;;;;;;;;;GASG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,gCAAgB;IACtD;QACE,KAAK,EAAE,CAAC;QACR,0EAA0E;QAC1E,wEAAwE;QACxE,2DAA2D;QAC3D,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC;IACvC,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK;QACV,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;YACzB,IAAI,CAAC,IAAI,6BAAgB,CAAC,oBAAoB,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QAClF,CAAC,CAAC;IACJ,CAAC;CACF,CAAA;AAlBY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,eAAU,EAAC,gCAAgB,CAAC;;GAChB,kBAAkB,CAkB9B"}
@@ -1,25 +0,0 @@
1
- import * as express from 'express';
2
- import { ServerMiddleware, Request as sRequest } from '../interfaces.js';
3
- /**
4
- * Emits a `Server-Timing` response header so browsers / devtools can show
5
- * internal phase durations alongside the network waterfall.
6
- *
7
- * By default it emits a single `total;dur=<ms>` entry. Other code can push
8
- * additional entries during the request:
9
- *
10
- * req.storage.serverTiming.push({ name: 'db', dur: 12, desc: 'main query' });
11
- *
12
- * Header is written by monkey-patching `res.end` so it lands on the response
13
- * regardless of how the controller flushed — Express ServerMiddleware.after()
14
- * does not run for normal route responses.
15
- *
16
- * Config:
17
- * http.serverTiming.enabled (default true)
18
- */
19
- export declare class ServerTiming extends ServerMiddleware {
20
- protected Enabled: boolean;
21
- constructor();
22
- before(): ((req: sRequest, res: express.Response, next: express.NextFunction) => void) | null;
23
- after(): null;
24
- }
25
- //# sourceMappingURL=ServerTiming.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ServerTiming.d.ts","sourceRoot":"","sources":["../../../src/middlewares/ServerTiming.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,QAAQ,EAAsB,MAAM,kBAAkB,CAAC;AAE7F;;;;;;;;;;;;;;;GAeG;AACH,qBACa,YAAa,SAAQ,gBAAgB;IAEhD,SAAS,CAAC,OAAO,EAAG,OAAO,CAAC;;IAOrB,MAAM,IAAI,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,YAAY,KAAK,IAAI,CAAC,GAAG,IAAI;IAoB7F,KAAK,IAAI,IAAI;CAGrB"}
@@ -1,78 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ServerTiming = void 0;
13
- const di_1 = require("@spinajs/di");
14
- const configuration_1 = require("@spinajs/configuration");
15
- const interfaces_js_1 = require("../interfaces.js");
16
- /**
17
- * Emits a `Server-Timing` response header so browsers / devtools can show
18
- * internal phase durations alongside the network waterfall.
19
- *
20
- * By default it emits a single `total;dur=<ms>` entry. Other code can push
21
- * additional entries during the request:
22
- *
23
- * req.storage.serverTiming.push({ name: 'db', dur: 12, desc: 'main query' });
24
- *
25
- * Header is written by monkey-patching `res.end` so it lands on the response
26
- * regardless of how the controller flushed — Express ServerMiddleware.after()
27
- * does not run for normal route responses.
28
- *
29
- * Config:
30
- * http.serverTiming.enabled (default true)
31
- */
32
- let ServerTiming = class ServerTiming extends interfaces_js_1.ServerMiddleware {
33
- constructor() {
34
- super();
35
- this.Order = 2;
36
- }
37
- before() {
38
- if (!this.Enabled)
39
- return null;
40
- return (req, res, next) => {
41
- const startedAt = Date.now();
42
- req.storage.serverTiming = req.storage.serverTiming ?? [];
43
- const originalEnd = res.end.bind(res);
44
- res.end = function patchedEnd(...args) {
45
- if (!res.headersSent) {
46
- const entries = req.storage.serverTiming ?? [];
47
- entries.push({ name: 'total', dur: Date.now() - startedAt });
48
- res.setHeader('Server-Timing', entries.map(formatEntry).join(', '));
49
- }
50
- return originalEnd(...args);
51
- };
52
- next();
53
- };
54
- }
55
- after() {
56
- return null;
57
- }
58
- };
59
- exports.ServerTiming = ServerTiming;
60
- __decorate([
61
- (0, configuration_1.Config)('http.serverTiming.enabled', { defaultValue: true }),
62
- __metadata("design:type", Boolean)
63
- ], ServerTiming.prototype, "Enabled", void 0);
64
- exports.ServerTiming = ServerTiming = __decorate([
65
- (0, di_1.Injectable)(interfaces_js_1.ServerMiddleware),
66
- __metadata("design:paramtypes", [])
67
- ], ServerTiming);
68
- function formatEntry(e) {
69
- // Per the RFC each metric is "name;dur=<ms>;desc=\"...\"" — quotes are
70
- // required when the description contains anything but ASCII identifiers.
71
- const parts = [e.name];
72
- if (typeof e.dur === 'number')
73
- parts.push(`dur=${e.dur}`);
74
- if (e.desc)
75
- parts.push(`desc="${e.desc.replace(/"/g, '\\"')}"`);
76
- return parts.join(';');
77
- }
78
- //# sourceMappingURL=ServerTiming.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ServerTiming.js","sourceRoot":"","sources":["../../../src/middlewares/ServerTiming.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA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AC,2BAA2B,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;;6CAChC;uBAFjB,YAAY;IADxB,IAAA,eAAU,EAAC,gCAAgB,CAAC;;GAChB,YAAY,CAgCxB;AAED,SAAS,WAAW,CAAC,CAAqB;IACxC,uEAAuE;IACvE,yEAAyE;IACzE,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,OAAO,CAAC,CAAC,GAAG,KAAK,QAAQ;QAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IAC1D,IAAI,CAAC,CAAC,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAChE,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
@@ -1,20 +0,0 @@
1
- import * as express from 'express';
2
- import { Log } from '@spinajs/log';
3
- import { ServerMiddleware, Request as sRequest } from '../interfaces.js';
4
- /**
5
- * Logs a warning when a request exceeds a configurable duration threshold.
6
- * Cheap diagnostic visibility for performance regressions.
7
- *
8
- * Config:
9
- * http.slowRequest.enabled (default true)
10
- * http.slowRequest.thresholdMs (default 1000)
11
- */
12
- export declare class SlowRequestWarning extends ServerMiddleware {
13
- protected Enabled: boolean;
14
- protected ThresholdMs: number;
15
- protected Log: Log;
16
- constructor();
17
- before(): ((req: sRequest, res: express.Response, next: express.NextFunction) => void) | null;
18
- after(): null;
19
- }
20
- //# sourceMappingURL=SlowRequestWarning.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SlowRequestWarning.d.ts","sourceRoot":"","sources":["../../../src/middlewares/SlowRequestWarning.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,OAAO,EAAU,GAAG,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEzE;;;;;;;GAOG;AACH,qBACa,kBAAmB,SAAQ,gBAAgB;IAEtD,SAAS,CAAC,OAAO,EAAG,OAAO,CAAC;IAG5B,SAAS,CAAC,WAAW,EAAG,MAAM,CAAC;IAG/B,SAAS,CAAC,GAAG,EAAG,GAAG,CAAC;;IAOb,MAAM,IAAI,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,YAAY,KAAK,IAAI,CAAC,GAAG,IAAI;IAuB7F,KAAK,IAAI,IAAI;CAGrB"}