@aomex/response-time 0.0.1
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 +11 -0
- package/LICENSE +21 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @aomex/response-time
|
|
2
|
+
|
|
3
|
+
## 0.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`c6be50a`](https://github.com/aomex/aomex/commit/c6be50a1908e93ed34a32c87cb75242b77e2f887) Thanks [@geekact](https://github.com/geekact)! - 增加 web 插件 response-time
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`4735157`](https://github.com/aomex/aomex/commit/4735157c52d0abecc41d6c7f416280ebfd6ee696), [`d6ac7b5`](https://github.com/aomex/aomex/commit/d6ac7b5403334b51fa15dbe82dd6b5b6d048f661), [`9254754`](https://github.com/aomex/aomex/commit/9254754d234fc0062eb5d600284ee8453825306c), [`d1ce4e2`](https://github.com/aomex/aomex/commit/d1ce4e2276f93c44e67ea06666d048917fa94e53), [`6056f55`](https://github.com/aomex/aomex/commit/6056f556577865220d6b5be2a4eafad9e4dbf8d4), [`1c67399`](https://github.com/aomex/aomex/commit/1c673992c4b313c2accb4cbc1fc66537a9886c29), [`352642a`](https://github.com/aomex/aomex/commit/352642abf2ccb3fe97e2d83a691d8428ccfc9758)]:
|
|
10
|
+
- @aomex/web@0.0.3
|
|
11
|
+
- @aomex/core@0.0.2
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 geekact
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WebMiddleware } from '@aomex/web';
|
|
2
|
+
|
|
3
|
+
interface ResponseTimeOptions {
|
|
4
|
+
/**
|
|
5
|
+
* `true` 则使用微妙,`false` 则使用毫秒(默认:true)
|
|
6
|
+
*/
|
|
7
|
+
hrtime?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const responseTime: (options?: ResponseTimeOptions) => WebMiddleware;
|
|
10
|
+
|
|
11
|
+
export { ResponseTimeOptions, responseTime };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { middleware } from "@aomex/core";
|
|
3
|
+
var responseTime = (options = {}) => {
|
|
4
|
+
const { hrtime = true } = options;
|
|
5
|
+
return middleware.web(async (ctx, next) => {
|
|
6
|
+
const start = process.hrtime();
|
|
7
|
+
try {
|
|
8
|
+
await next();
|
|
9
|
+
} finally {
|
|
10
|
+
const deltas = process.hrtime(start);
|
|
11
|
+
let delta = deltas[0] * 1e3 + deltas[1] / 1e6;
|
|
12
|
+
if (!hrtime) {
|
|
13
|
+
delta = Math.round(delta);
|
|
14
|
+
}
|
|
15
|
+
ctx.response.setHeader("X-Response-Time", delta + "ms");
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
responseTime
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { middleware } from '@aomex/core';\nimport type { WebMiddleware } from '@aomex/web';\n\nexport interface ResponseTimeOptions {\n /**\n * `true` 则使用微妙,`false` 则使用毫秒(默认:true)\n */\n hrtime?: boolean;\n}\n\nexport const responseTime = (\n options: ResponseTimeOptions = {},\n): WebMiddleware => {\n const { hrtime = true } = options;\n\n return middleware.web(async (ctx, next) => {\n const start = process.hrtime();\n\n try {\n await next();\n } finally {\n const deltas = process.hrtime(start);\n let delta = deltas[0] * 1000 + deltas[1] / 1000000;\n\n if (!hrtime) {\n delta = Math.round(delta);\n }\n\n ctx.response.setHeader('X-Response-Time', delta + 'ms');\n }\n });\n};\n"],"mappings":";AAAA,SAAS,kBAAkB;AAUpB,IAAM,eAAe,CAC1B,UAA+B,CAAC,MACd;AAClB,QAAM,EAAE,SAAS,KAAK,IAAI;AAE1B,SAAO,WAAW,IAAI,OAAO,KAAK,SAAS;AACzC,UAAM,QAAQ,QAAQ,OAAO;AAE7B,QAAI;AACF,YAAM,KAAK;AAAA,IACb,UAAE;AACA,YAAM,SAAS,QAAQ,OAAO,KAAK;AACnC,UAAI,QAAQ,OAAO,CAAC,IAAI,MAAO,OAAO,CAAC,IAAI;AAE3C,UAAI,CAAC,QAAQ;AACX,gBAAQ,KAAK,MAAM,KAAK;AAAA,MAC1B;AAEA,UAAI,SAAS,UAAU,mBAAmB,QAAQ,IAAI;AAAA,IACxD;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aomex/response-time",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "在headers里查看请求花费的时间",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"repository": "git@github.com:aomex/aomex.git",
|
|
7
|
+
"homepage": "https://aomex.js.org",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"package.json",
|
|
23
|
+
"README.md",
|
|
24
|
+
"CHANGELOG.md"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@aomex/core": "^0.0.2",
|
|
31
|
+
"@aomex/web": "^0.0.3"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@aomex/core": "^0.0.2",
|
|
35
|
+
"@aomex/web": "^0.0.3",
|
|
36
|
+
"@types/supertest": "^2.0.12",
|
|
37
|
+
"supertest": "^6.2.4",
|
|
38
|
+
"vitest": "^0.28.4"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {}
|
|
41
|
+
}
|