@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.
- package/lib/cjs/cache.d.ts +9 -10
- package/lib/cjs/cache.d.ts.map +1 -1
- package/lib/cjs/cache.js +41 -86
- package/lib/cjs/cache.js.map +1 -1
- package/lib/cjs/controllers.d.ts +3 -33
- package/lib/cjs/controllers.d.ts.map +1 -1
- package/lib/cjs/controllers.js +70 -97
- package/lib/cjs/controllers.js.map +1 -1
- package/lib/cjs/decorators.d.ts.map +1 -1
- package/lib/cjs/decorators.js +0 -55
- package/lib/cjs/decorators.js.map +1 -1
- package/lib/cjs/index.d.ts +0 -7
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +0 -7
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces.d.ts +1 -27
- package/lib/cjs/interfaces.d.ts.map +1 -1
- package/lib/cjs/interfaces.js.map +1 -1
- package/lib/cjs/server.d.ts +0 -7
- package/lib/cjs/server.d.ts.map +1 -1
- package/lib/cjs/server.js +24 -9
- package/lib/cjs/server.js.map +1 -1
- package/lib/mjs/cache.d.ts +9 -10
- package/lib/mjs/cache.d.ts.map +1 -1
- package/lib/mjs/cache.js +41 -86
- package/lib/mjs/cache.js.map +1 -1
- package/lib/mjs/controllers.d.ts +3 -33
- package/lib/mjs/controllers.d.ts.map +1 -1
- package/lib/mjs/controllers.js +39 -99
- package/lib/mjs/controllers.js.map +1 -1
- package/lib/mjs/decorators.d.ts.map +1 -1
- package/lib/mjs/decorators.js +0 -55
- package/lib/mjs/decorators.js.map +1 -1
- package/lib/mjs/index.d.ts +0 -7
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +0 -7
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/interfaces.d.ts +1 -27
- package/lib/mjs/interfaces.d.ts.map +1 -1
- package/lib/mjs/interfaces.js.map +1 -1
- package/lib/mjs/server.d.ts +0 -7
- package/lib/mjs/server.d.ts.map +1 -1
- package/lib/mjs/server.js +24 -9
- package/lib/mjs/server.js.map +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +11 -11
- package/lib/cjs/middlewares/AccessLog.d.ts +0 -23
- package/lib/cjs/middlewares/AccessLog.d.ts.map +0 -1
- package/lib/cjs/middlewares/AccessLog.js +0 -73
- package/lib/cjs/middlewares/AccessLog.js.map +0 -1
- package/lib/cjs/middlewares/Compression.d.ts +0 -21
- package/lib/cjs/middlewares/Compression.d.ts.map +0 -1
- package/lib/cjs/middlewares/Compression.js +0 -62
- package/lib/cjs/middlewares/Compression.js.map +0 -1
- package/lib/cjs/middlewares/Cors.d.ts +0 -25
- package/lib/cjs/middlewares/Cors.d.ts.map +0 -1
- package/lib/cjs/middlewares/Cors.js +0 -81
- package/lib/cjs/middlewares/Cors.js.map +0 -1
- package/lib/cjs/middlewares/ErrorHandler.d.ts +0 -17
- package/lib/cjs/middlewares/ErrorHandler.d.ts.map +0 -1
- package/lib/cjs/middlewares/ErrorHandler.js +0 -42
- package/lib/cjs/middlewares/ErrorHandler.js.map +0 -1
- package/lib/cjs/middlewares/NotFound.d.ts +0 -18
- package/lib/cjs/middlewares/NotFound.d.ts.map +0 -1
- package/lib/cjs/middlewares/NotFound.js +0 -48
- package/lib/cjs/middlewares/NotFound.js.map +0 -1
- package/lib/cjs/middlewares/ServerTiming.d.ts +0 -25
- package/lib/cjs/middlewares/ServerTiming.d.ts.map +0 -1
- package/lib/cjs/middlewares/ServerTiming.js +0 -78
- package/lib/cjs/middlewares/ServerTiming.js.map +0 -1
- package/lib/cjs/middlewares/SlowRequestWarning.d.ts +0 -20
- package/lib/cjs/middlewares/SlowRequestWarning.d.ts.map +0 -1
- package/lib/cjs/middlewares/SlowRequestWarning.js +0 -74
- package/lib/cjs/middlewares/SlowRequestWarning.js.map +0 -1
- package/lib/mjs/middlewares/AccessLog.d.ts +0 -23
- package/lib/mjs/middlewares/AccessLog.d.ts.map +0 -1
- package/lib/mjs/middlewares/AccessLog.js +0 -70
- package/lib/mjs/middlewares/AccessLog.js.map +0 -1
- package/lib/mjs/middlewares/Compression.d.ts +0 -21
- package/lib/mjs/middlewares/Compression.d.ts.map +0 -1
- package/lib/mjs/middlewares/Compression.js +0 -56
- package/lib/mjs/middlewares/Compression.js.map +0 -1
- package/lib/mjs/middlewares/Cors.d.ts +0 -25
- package/lib/mjs/middlewares/Cors.d.ts.map +0 -1
- package/lib/mjs/middlewares/Cors.js +0 -75
- package/lib/mjs/middlewares/Cors.js.map +0 -1
- package/lib/mjs/middlewares/ErrorHandler.d.ts +0 -17
- package/lib/mjs/middlewares/ErrorHandler.d.ts.map +0 -1
- package/lib/mjs/middlewares/ErrorHandler.js +0 -39
- package/lib/mjs/middlewares/ErrorHandler.js.map +0 -1
- package/lib/mjs/middlewares/NotFound.d.ts +0 -18
- package/lib/mjs/middlewares/NotFound.d.ts.map +0 -1
- package/lib/mjs/middlewares/NotFound.js +0 -45
- package/lib/mjs/middlewares/NotFound.js.map +0 -1
- package/lib/mjs/middlewares/ServerTiming.d.ts +0 -25
- package/lib/mjs/middlewares/ServerTiming.d.ts.map +0 -1
- package/lib/mjs/middlewares/ServerTiming.js +0 -75
- package/lib/mjs/middlewares/ServerTiming.js.map +0 -1
- package/lib/mjs/middlewares/SlowRequestWarning.d.ts +0 -20
- package/lib/mjs/middlewares/SlowRequestWarning.d.ts.map +0 -1
- package/lib/mjs/middlewares/SlowRequestWarning.js +0 -71
- package/lib/mjs/middlewares/SlowRequestWarning.js.map +0 -1
|
@@ -1,74 +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.SlowRequestWarning = 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
|
-
* Logs a warning when a request exceeds a configurable duration threshold.
|
|
19
|
-
* Cheap diagnostic visibility for performance regressions.
|
|
20
|
-
*
|
|
21
|
-
* Config:
|
|
22
|
-
* http.slowRequest.enabled (default true)
|
|
23
|
-
* http.slowRequest.thresholdMs (default 1000)
|
|
24
|
-
*/
|
|
25
|
-
let SlowRequestWarning = class SlowRequestWarning extends interfaces_js_1.ServerMiddleware {
|
|
26
|
-
constructor() {
|
|
27
|
-
super();
|
|
28
|
-
this.Order = 2;
|
|
29
|
-
}
|
|
30
|
-
before() {
|
|
31
|
-
if (!this.Enabled)
|
|
32
|
-
return null;
|
|
33
|
-
const log = this.Log;
|
|
34
|
-
const threshold = this.ThresholdMs;
|
|
35
|
-
return (req, res, next) => {
|
|
36
|
-
const startedAt = Date.now();
|
|
37
|
-
res.on('finish', () => {
|
|
38
|
-
const ms = Date.now() - startedAt;
|
|
39
|
-
if (ms >= threshold) {
|
|
40
|
-
log.warn(`Slow request: ${req.method} ${req.originalUrl} took ${ms}ms (threshold ${threshold}ms)`, {
|
|
41
|
-
method: req.method,
|
|
42
|
-
path: req.originalUrl,
|
|
43
|
-
ms,
|
|
44
|
-
threshold,
|
|
45
|
-
status: res.statusCode,
|
|
46
|
-
requestId: req.storage?.requestId,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
next();
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
after() {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
exports.SlowRequestWarning = SlowRequestWarning;
|
|
58
|
-
__decorate([
|
|
59
|
-
(0, configuration_1.Config)('http.slowRequest.enabled', { defaultValue: true }),
|
|
60
|
-
__metadata("design:type", Boolean)
|
|
61
|
-
], SlowRequestWarning.prototype, "Enabled", void 0);
|
|
62
|
-
__decorate([
|
|
63
|
-
(0, configuration_1.Config)('http.slowRequest.thresholdMs', { defaultValue: 1000 }),
|
|
64
|
-
__metadata("design:type", Number)
|
|
65
|
-
], SlowRequestWarning.prototype, "ThresholdMs", void 0);
|
|
66
|
-
__decorate([
|
|
67
|
-
(0, log_1.Logger)('http'),
|
|
68
|
-
__metadata("design:type", log_1.Log)
|
|
69
|
-
], SlowRequestWarning.prototype, "Log", void 0);
|
|
70
|
-
exports.SlowRequestWarning = SlowRequestWarning = __decorate([
|
|
71
|
-
(0, di_1.Injectable)(interfaces_js_1.ServerMiddleware),
|
|
72
|
-
__metadata("design:paramtypes", [])
|
|
73
|
-
], SlowRequestWarning);
|
|
74
|
-
//# sourceMappingURL=SlowRequestWarning.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SlowRequestWarning.js","sourceRoot":"","sources":["../../../src/middlewares/SlowRequestWarning.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAAyC;AACzC,0DAAgD;AAChD,sCAA2C;AAE3C,oDAAyE;AAEzE;;;;;;;GAOG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,gCAAgB;IAUtD;QACE,KAAK,EAAE,CAAC;QACR,IAAI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;IAD9B,IAAA,eAAU,EAAC,gCAAgB,CAAC;;GAChB,kBAAkB,CAyC9B"}
|
|
@@ -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,70 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
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;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Injectable } from '@spinajs/di';
|
|
11
|
-
import { Config } from '@spinajs/configuration';
|
|
12
|
-
import { Logger, Log } from '@spinajs/log';
|
|
13
|
-
import { ServerMiddleware } from '../interfaces.js';
|
|
14
|
-
/**
|
|
15
|
-
* Emits one structured log line per HTTP request.
|
|
16
|
-
*
|
|
17
|
-
* Pairs with RequestId / RealIp / ResponseTime: the line includes
|
|
18
|
-
* `requestId`, `ip`, and `ms` populated by those middlewares. The log is
|
|
19
|
-
* emitted on the response's `finish` event so it captures the final status
|
|
20
|
-
* code and reflects the actual time spent.
|
|
21
|
-
*
|
|
22
|
-
* Config:
|
|
23
|
-
* http.accessLog.enabled (default true)
|
|
24
|
-
* http.accessLog.logger (default 'http.access')
|
|
25
|
-
*/
|
|
26
|
-
let AccessLog = class AccessLog extends ServerMiddleware {
|
|
27
|
-
constructor() {
|
|
28
|
-
super();
|
|
29
|
-
// Needs req.storage to exist (ReqStorage = -2), so any Order > -2 is fine.
|
|
30
|
-
// Sit alongside RealIp / RequestId.
|
|
31
|
-
this.Order = 2;
|
|
32
|
-
}
|
|
33
|
-
before() {
|
|
34
|
-
if (!this.Enabled)
|
|
35
|
-
return null;
|
|
36
|
-
const log = this.Log;
|
|
37
|
-
return (req, res, next) => {
|
|
38
|
-
const startedAt = Date.now();
|
|
39
|
-
res.on('finish', () => {
|
|
40
|
-
log.info(`${req.method} ${req.originalUrl} ${res.statusCode} ${Date.now() - startedAt}ms`, {
|
|
41
|
-
method: req.method,
|
|
42
|
-
path: req.originalUrl,
|
|
43
|
-
status: res.statusCode,
|
|
44
|
-
ms: Date.now() - startedAt,
|
|
45
|
-
ip: req.storage?.realIp,
|
|
46
|
-
requestId: req.storage?.requestId,
|
|
47
|
-
userAgent: req.headers['user-agent'],
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
next();
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
after() {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
__decorate([
|
|
58
|
-
Config('http.accessLog.enabled', { defaultValue: true }),
|
|
59
|
-
__metadata("design:type", Boolean)
|
|
60
|
-
], AccessLog.prototype, "Enabled", void 0);
|
|
61
|
-
__decorate([
|
|
62
|
-
Logger('http.access'),
|
|
63
|
-
__metadata("design:type", Log)
|
|
64
|
-
], AccessLog.prototype, "Log", void 0);
|
|
65
|
-
AccessLog = __decorate([
|
|
66
|
-
Injectable(ServerMiddleware),
|
|
67
|
-
__metadata("design:paramtypes", [])
|
|
68
|
-
], AccessLog);
|
|
69
|
-
export { AccessLog };
|
|
70
|
-
//# sourceMappingURL=AccessLog.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AccessLog.js","sourceRoot":"","sources":["../../../src/middlewares/AccessLog.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,UAAU,EAAE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,CAAC;IAEM,KAAK;QACV,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAnCW;IADT,MAAM,CAAC,wBAAwB,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;;0CAC7B;AAGlB;IADT,MAAM,CAAC,aAAa,CAAC;8BACN,GAAG;sCAAC;AALT,SAAS;IADrB,UAAU,CAAC,gBAAgB,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,56 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
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;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Injectable } from '@spinajs/di';
|
|
11
|
-
import { Config } from '@spinajs/configuration';
|
|
12
|
-
import compression from 'compression';
|
|
13
|
-
import { ServerMiddleware } from '../interfaces.js';
|
|
14
|
-
/**
|
|
15
|
-
* Gzip/brotli compression of response bodies via the `compression` npm
|
|
16
|
-
* package, wrapped as a ServerMiddleware so it plugs into the standard
|
|
17
|
-
* lifecycle rather than being wired manually in `http.middlewares` config.
|
|
18
|
-
*
|
|
19
|
-
* Config:
|
|
20
|
-
* http.compression.enabled (default true)
|
|
21
|
-
* http.compression.threshold (default 1024, bytes — bodies below skipped)
|
|
22
|
-
* http.compression.level (default -1, zlib default)
|
|
23
|
-
*/
|
|
24
|
-
let Compression = class Compression extends ServerMiddleware {
|
|
25
|
-
constructor() {
|
|
26
|
-
super();
|
|
27
|
-
// Run early so the response stream is wrapped before controllers write.
|
|
28
|
-
this.Order = 0;
|
|
29
|
-
}
|
|
30
|
-
before() {
|
|
31
|
-
if (!this.Enabled)
|
|
32
|
-
return null;
|
|
33
|
-
return compression({ threshold: this.Threshold, level: this.Level });
|
|
34
|
-
}
|
|
35
|
-
after() {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
__decorate([
|
|
40
|
-
Config('http.compression.enabled', { defaultValue: true }),
|
|
41
|
-
__metadata("design:type", Boolean)
|
|
42
|
-
], Compression.prototype, "Enabled", void 0);
|
|
43
|
-
__decorate([
|
|
44
|
-
Config('http.compression.threshold', { defaultValue: 1024 }),
|
|
45
|
-
__metadata("design:type", Number)
|
|
46
|
-
], Compression.prototype, "Threshold", void 0);
|
|
47
|
-
__decorate([
|
|
48
|
-
Config('http.compression.level', { defaultValue: -1 }),
|
|
49
|
-
__metadata("design:type", Number)
|
|
50
|
-
], Compression.prototype, "Level", void 0);
|
|
51
|
-
Compression = __decorate([
|
|
52
|
-
Injectable(ServerMiddleware),
|
|
53
|
-
__metadata("design:paramtypes", [])
|
|
54
|
-
], Compression);
|
|
55
|
-
export { Compression };
|
|
56
|
-
//# sourceMappingURL=Compression.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Compression.js","sourceRoot":"","sources":["../../../src/middlewares/Compression.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,WAAW,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAuB,MAAM,kBAAkB,CAAC;AAEzE;;;;;;;;;GASG;AAEI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,gBAAgB;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,WAAW,CAAC,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;AAtBW;IADT,MAAM,CAAC,0BAA0B,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;;4CAC/B;AAGlB;IADT,MAAM,CAAC,4BAA4B,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;;8CAChC;AAGnB;IADT,MAAM,CAAC,wBAAwB,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC;;0CAC9B;AARd,WAAW;IADvB,UAAU,CAAC,gBAAgB,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,75 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
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;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import cors from 'cors';
|
|
11
|
-
import { Injectable, Container, Autoinject } from '@spinajs/di';
|
|
12
|
-
import { Configuration } from '@spinajs/configuration';
|
|
13
|
-
import { Logger, Log } from '@spinajs/log';
|
|
14
|
-
import { ServerMiddleware } from '../interfaces.js';
|
|
15
|
-
/**
|
|
16
|
-
* CORS middleware extracted verbatim from the previous inline block in
|
|
17
|
-
* `HttpServer.resolve()`. Behavior unchanged — same `http.cors` config keys,
|
|
18
|
-
* same warning when missing, same origin matching. Lives here so it can be
|
|
19
|
-
* tested, replaced, or disabled like any other ServerMiddleware.
|
|
20
|
-
*
|
|
21
|
-
* Config:
|
|
22
|
-
* http.cors.origins (string[]; empty/missing allows all)
|
|
23
|
-
* http.cors.exposedHeaders (string[])
|
|
24
|
-
* http.cors.allowedHeaders (string[])
|
|
25
|
-
*/
|
|
26
|
-
let CorsMiddleware = class CorsMiddleware extends ServerMiddleware {
|
|
27
|
-
constructor() {
|
|
28
|
-
super();
|
|
29
|
-
// Must run early — preflight needs to short-circuit before any business
|
|
30
|
-
// middleware. Sit just after RequestStorage (-2) and ResponseTime (-1).
|
|
31
|
-
this.Order = -1;
|
|
32
|
-
}
|
|
33
|
-
before() {
|
|
34
|
-
const cOptions = this.Configuration.get('http.cors', undefined);
|
|
35
|
-
if (!cOptions) {
|
|
36
|
-
this.Log.warn(`CORS options not set, server may be unavaible from outside ! Please set http.cors configuration option.`);
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
const corsOptions = {
|
|
40
|
-
origin(origin, callback) {
|
|
41
|
-
if (!cOptions || cOptions.origins.length === 0 || cOptions.origins.indexOf(origin) !== -1) {
|
|
42
|
-
callback(null, true);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
callback(new Error('cors not allowed'));
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
exposedHeaders: cOptions.exposedHeaders,
|
|
49
|
-
allowedHeaders: cOptions.allowedHeaders,
|
|
50
|
-
credentials: true,
|
|
51
|
-
};
|
|
52
|
-
return cors(corsOptions);
|
|
53
|
-
}
|
|
54
|
-
after() {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
__decorate([
|
|
59
|
-
Autoinject(Container),
|
|
60
|
-
__metadata("design:type", Object)
|
|
61
|
-
], CorsMiddleware.prototype, "Container", void 0);
|
|
62
|
-
__decorate([
|
|
63
|
-
Autoinject(Configuration),
|
|
64
|
-
__metadata("design:type", Configuration)
|
|
65
|
-
], CorsMiddleware.prototype, "Configuration", void 0);
|
|
66
|
-
__decorate([
|
|
67
|
-
Logger('http'),
|
|
68
|
-
__metadata("design:type", Log)
|
|
69
|
-
], CorsMiddleware.prototype, "Log", void 0);
|
|
70
|
-
CorsMiddleware = __decorate([
|
|
71
|
-
Injectable(ServerMiddleware),
|
|
72
|
-
__metadata("design:paramtypes", [])
|
|
73
|
-
], CorsMiddleware);
|
|
74
|
-
export { CorsMiddleware };
|
|
75
|
-
//# sourceMappingURL=Cors.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Cors.js","sourceRoot":"","sources":["../../../src/middlewares/Cors.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAc,UAAU,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,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A,aAAa;qDAAC;AAG9B;IADT,MAAM,CAAC,MAAM,CAAC;8BACC,GAAG;2CAAC;AART,cAAc;IAD1B,UAAU,CAAC,gBAAgB,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,39 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
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;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Injectable } from '@spinajs/di';
|
|
11
|
-
import { ServerMiddleware } from '../interfaces.js';
|
|
12
|
-
import { __handle_error__ } from '../error.js';
|
|
13
|
-
/**
|
|
14
|
-
* Last-resort error handler. Wraps the existing `__handle_error__` factory
|
|
15
|
-
* (which produces a 4-arg Express error middleware that maps errors to
|
|
16
|
-
* configured HTTP responses) into the standard ServerMiddleware lifecycle.
|
|
17
|
-
*
|
|
18
|
-
* Order MIN_SAFE_INTEGER places it at the very tail of the Express stack
|
|
19
|
-
* after `HttpServer.start()` reverses by Order — exactly where Express
|
|
20
|
-
* expects error middleware to live.
|
|
21
|
-
*/
|
|
22
|
-
let ErrorHandlerMiddleware = class ErrorHandlerMiddleware extends ServerMiddleware {
|
|
23
|
-
constructor() {
|
|
24
|
-
super();
|
|
25
|
-
this.Order = Number.MIN_SAFE_INTEGER - 1;
|
|
26
|
-
}
|
|
27
|
-
before() {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
after() {
|
|
31
|
-
return __handle_error__();
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
ErrorHandlerMiddleware = __decorate([
|
|
35
|
-
Injectable(ServerMiddleware),
|
|
36
|
-
__metadata("design:paramtypes", [])
|
|
37
|
-
], ErrorHandlerMiddleware);
|
|
38
|
-
export { ErrorHandlerMiddleware };
|
|
39
|
-
//# sourceMappingURL=ErrorHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorHandler.js","sourceRoot":"","sources":["../../../src/middlewares/ErrorHandler.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;;GAQG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,gBAAgB;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,gBAAgB,EAAE,CAAC;IAC5B,CAAC;CACF,CAAA;AAbY,sBAAsB;IADlC,UAAU,CAAC,gBAAgB,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,45 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
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;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Injectable } from '@spinajs/di';
|
|
11
|
-
import { ResourceNotFound } from '@spinajs/exceptions';
|
|
12
|
-
import { ServerMiddleware } from '../interfaces.js';
|
|
13
|
-
/**
|
|
14
|
-
* Catches requests that no controller route matched and turns them into a
|
|
15
|
-
* standard ResourceNotFound error so {@link ErrorHandlerMiddleware} can
|
|
16
|
-
* produce a proper HTTP response.
|
|
17
|
-
*
|
|
18
|
-
* Registered as a normal ServerMiddleware so it participates in the
|
|
19
|
-
* established lifecycle (HttpServer.start() reverses by Order and applies
|
|
20
|
-
* after()). Its Order is one step above MIN_SAFE_INTEGER so it lands at the
|
|
21
|
-
* Express stack tail, just before the error handler.
|
|
22
|
-
*/
|
|
23
|
-
let NotFoundMiddleware = class NotFoundMiddleware extends ServerMiddleware {
|
|
24
|
-
constructor() {
|
|
25
|
-
super();
|
|
26
|
-
// Reverse-iteration over after() means lowest Order runs LAST and ends up
|
|
27
|
-
// at the Express stack tail. We want NotFound right before ErrorHandler
|
|
28
|
-
// (which uses MIN_SAFE_INTEGER), so we sit one step above.
|
|
29
|
-
this.Order = Number.MIN_SAFE_INTEGER;
|
|
30
|
-
}
|
|
31
|
-
before() {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
after() {
|
|
35
|
-
return (req, _res, next) => {
|
|
36
|
-
next(new ResourceNotFound(`Route not found: ${req.method} ${req.originalUrl}`));
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
NotFoundMiddleware = __decorate([
|
|
41
|
-
Injectable(ServerMiddleware),
|
|
42
|
-
__metadata("design:paramtypes", [])
|
|
43
|
-
], NotFoundMiddleware);
|
|
44
|
-
export { NotFoundMiddleware };
|
|
45
|
-
//# sourceMappingURL=NotFound.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NotFound.js","sourceRoot":"","sources":["../../../src/middlewares/NotFound.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;;;;GASG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,gBAAgB;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,gBAAgB,CAAC,oBAAoB,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QAClF,CAAC,CAAC;IACJ,CAAC;CACF,CAAA;AAlBY,kBAAkB;IAD9B,UAAU,CAAC,gBAAgB,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,75 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
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;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Injectable } from '@spinajs/di';
|
|
11
|
-
import { Config } from '@spinajs/configuration';
|
|
12
|
-
import { ServerMiddleware } from '../interfaces.js';
|
|
13
|
-
/**
|
|
14
|
-
* Emits a `Server-Timing` response header so browsers / devtools can show
|
|
15
|
-
* internal phase durations alongside the network waterfall.
|
|
16
|
-
*
|
|
17
|
-
* By default it emits a single `total;dur=<ms>` entry. Other code can push
|
|
18
|
-
* additional entries during the request:
|
|
19
|
-
*
|
|
20
|
-
* req.storage.serverTiming.push({ name: 'db', dur: 12, desc: 'main query' });
|
|
21
|
-
*
|
|
22
|
-
* Header is written by monkey-patching `res.end` so it lands on the response
|
|
23
|
-
* regardless of how the controller flushed — Express ServerMiddleware.after()
|
|
24
|
-
* does not run for normal route responses.
|
|
25
|
-
*
|
|
26
|
-
* Config:
|
|
27
|
-
* http.serverTiming.enabled (default true)
|
|
28
|
-
*/
|
|
29
|
-
let ServerTiming = class ServerTiming extends ServerMiddleware {
|
|
30
|
-
constructor() {
|
|
31
|
-
super();
|
|
32
|
-
this.Order = 2;
|
|
33
|
-
}
|
|
34
|
-
before() {
|
|
35
|
-
if (!this.Enabled)
|
|
36
|
-
return null;
|
|
37
|
-
return (req, res, next) => {
|
|
38
|
-
const startedAt = Date.now();
|
|
39
|
-
req.storage.serverTiming = req.storage.serverTiming ?? [];
|
|
40
|
-
const originalEnd = res.end.bind(res);
|
|
41
|
-
res.end = function patchedEnd(...args) {
|
|
42
|
-
if (!res.headersSent) {
|
|
43
|
-
const entries = req.storage.serverTiming ?? [];
|
|
44
|
-
entries.push({ name: 'total', dur: Date.now() - startedAt });
|
|
45
|
-
res.setHeader('Server-Timing', entries.map(formatEntry).join(', '));
|
|
46
|
-
}
|
|
47
|
-
return originalEnd(...args);
|
|
48
|
-
};
|
|
49
|
-
next();
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
after() {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
__decorate([
|
|
57
|
-
Config('http.serverTiming.enabled', { defaultValue: true }),
|
|
58
|
-
__metadata("design:type", Boolean)
|
|
59
|
-
], ServerTiming.prototype, "Enabled", void 0);
|
|
60
|
-
ServerTiming = __decorate([
|
|
61
|
-
Injectable(ServerMiddleware),
|
|
62
|
-
__metadata("design:paramtypes", [])
|
|
63
|
-
], ServerTiming);
|
|
64
|
-
export { ServerTiming };
|
|
65
|
-
function formatEntry(e) {
|
|
66
|
-
// Per the RFC each metric is "name;dur=<ms>;desc=\"...\"" — quotes are
|
|
67
|
-
// required when the description contains anything but ASCII identifiers.
|
|
68
|
-
const parts = [e.name];
|
|
69
|
-
if (typeof e.dur === 'number')
|
|
70
|
-
parts.push(`dur=${e.dur}`);
|
|
71
|
-
if (e.desc)
|
|
72
|
-
parts.push(`desc="${e.desc.replace(/"/g, '\\"')}"`);
|
|
73
|
-
return parts.join(';');
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=ServerTiming.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ServerTiming.js","sourceRoot":"","sources":["../../../src/middlewares/ServerTiming.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAA2C,MAAM,kBAAkB,CAAC;AAE7F;;;;;;;;;;;;;;;GAeG;AAEI,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,gBAAgB;IAIhD;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;IACjB,CAAC;IAEM,MAAM;QACX,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QAC/B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YACxB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC7B,GAAG,CAAC,OAAO,CAAC,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;YAE1D,MAAM,WAAW,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAmB,CAAC;YACvD,GAAG,CAAC,GAAW,GAAG,SAAS,UAAU,CA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