0http-bun 1.0.4 → 1.1.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/lib/router/sequential.js +12 -2
- package/package.json +4 -3
package/lib/router/sequential.js
CHANGED
|
@@ -10,6 +10,8 @@ const STATUS_500 = {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
module.exports = (config = {}) => {
|
|
13
|
+
const cache = new Map()
|
|
14
|
+
|
|
13
15
|
if (!config.defaultRoute) {
|
|
14
16
|
config.defaultRoute = () => {
|
|
15
17
|
return new Response(null, STATUS_404)
|
|
@@ -45,8 +47,16 @@ module.exports = (config = {}) => {
|
|
|
45
47
|
req.path = path || '/'
|
|
46
48
|
req.query = queryIndex > 0 ? qs.parse(url.substring(queryIndex + 1)) : {}
|
|
47
49
|
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
+
const cacheKey = `${req.method}:${req.path}`
|
|
51
|
+
let match = null
|
|
52
|
+
if (cache.has(cacheKey)) {
|
|
53
|
+
match = cache.get(cacheKey)
|
|
54
|
+
} else {
|
|
55
|
+
match = router.find(req.method, req.path)
|
|
56
|
+
cache.set(cacheKey, match)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (match?.handlers?.length > 0) {
|
|
50
60
|
if (!req.params) {
|
|
51
61
|
req.params = {}
|
|
52
62
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "0http-bun",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "0http for Bun",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"lint": "bun x standard",
|
|
8
|
-
"format": "bun x standard --fix"
|
|
8
|
+
"format": "bun x standard --fix",
|
|
9
|
+
"test": "bun test"
|
|
9
10
|
},
|
|
10
11
|
"dependencies": {
|
|
11
12
|
"fast-querystring": "^1.1.2",
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"0http-bun": "^1.0.3",
|
|
28
29
|
"bun-types": "^1.1.8",
|
|
29
|
-
"mitata": "^0.
|
|
30
|
+
"mitata": "^1.0.32"
|
|
30
31
|
},
|
|
31
32
|
"keywords": [
|
|
32
33
|
"http",
|