@aomex/response-time 3.28.2 → 3.29.0
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/CHANGELOG.md +19 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.29.0](https://github.com/aomex/aomex/compare/v3.28.3...v3.29.0) (2025-07-17)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **response-time:** 中间件导出为函数类型 ([00d99e0](https://github.com/aomex/aomex/commit/00d99e0aa4566bd225fa73e7dbf839be2ac93d7c))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [3.28.3](https://github.com/aomex/aomex/compare/v3.28.2...v3.28.3) (2025-07-10)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @aomex/response-time
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [3.28.2](https://github.com/aomex/aomex/compare/v3.28.1...v3.28.2) (2025-07-09)
|
|
7
26
|
|
|
8
27
|
**Note:** Version bump only for package @aomex/response-time
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -4,18 +4,20 @@ var getDelta = (start) => {
|
|
|
4
4
|
const deltas = process.hrtime(start);
|
|
5
5
|
return deltas[0] * 1e3 + deltas[1] / 1e6 + "ms";
|
|
6
6
|
};
|
|
7
|
-
var responseTime =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
err
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
var responseTime = () => {
|
|
8
|
+
return middleware.web((ctx, next) => {
|
|
9
|
+
const start = process.hrtime();
|
|
10
|
+
return next().then(() => {
|
|
11
|
+
ctx.response.setHeader("x-response-time", getDelta(start));
|
|
12
|
+
}).catch((err) => {
|
|
13
|
+
err.headers = {
|
|
14
|
+
...err.headers,
|
|
15
|
+
"x-response-time": getDelta(start)
|
|
16
|
+
};
|
|
17
|
+
return Promise.reject(err);
|
|
18
|
+
});
|
|
17
19
|
});
|
|
18
|
-
}
|
|
20
|
+
};
|
|
19
21
|
export {
|
|
20
22
|
responseTime
|
|
21
23
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { middleware } from '@aomex/common';\nimport type { HttpError } from '@aomex/web';\n\nconst getDelta = (start: [number, number]) => {\n const deltas = process.hrtime(start);\n return deltas[0] * 1_000 + deltas[1] / 1_000_000 + 'ms';\n};\n\nexport const responseTime = middleware.web((ctx, next) => {\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { middleware } from '@aomex/common';\nimport type { HttpError } from '@aomex/web';\n\nconst getDelta = (start: [number, number]) => {\n const deltas = process.hrtime(start);\n return deltas[0] * 1_000 + deltas[1] / 1_000_000 + 'ms';\n};\n\nexport const responseTime = () => {\n return middleware.web((ctx, next) => {\n const start = process.hrtime();\n return next()\n .then(() => {\n ctx.response.setHeader('x-response-time', getDelta(start));\n })\n .catch((err: HttpError) => {\n err.headers = {\n ...err.headers,\n 'x-response-time': getDelta(start),\n };\n return Promise.reject(err);\n });\n });\n};\n"],"mappings":";AAAA,SAAS,kBAAkB;AAG3B,IAAM,WAAW,CAAC,UAA4B;AAC5C,QAAM,SAAS,QAAQ,OAAO,KAAK;AACnC,SAAO,OAAO,CAAC,IAAI,MAAQ,OAAO,CAAC,IAAI,MAAY;AACrD;AAEO,IAAM,eAAe,MAAM;AAChC,SAAO,WAAW,IAAI,CAAC,KAAK,SAAS;AACnC,UAAM,QAAQ,QAAQ,OAAO;AAC7B,WAAO,KAAK,EACT,KAAK,MAAM;AACV,UAAI,SAAS,UAAU,mBAAmB,SAAS,KAAK,CAAC;AAAA,IAC3D,CAAC,EACA,MAAM,CAAC,QAAmB;AACzB,UAAI,UAAU;AAAA,QACZ,GAAG,IAAI;AAAA,QACP,mBAAmB,SAAS,KAAK;AAAA,MACnC;AACA,aAAO,QAAQ,OAAO,GAAG;AAAA,IAC3B,CAAC;AAAA,EACL,CAAC;AACH;","names":[]}
|