@jayfong/x-server 1.34.4 → 1.34.6

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.
@@ -92,12 +92,12 @@ class Server {
92
92
 
93
93
  const routeMap = (0, _vtils.keyBy)(this.routes, item => item.path);
94
94
 
95
- const handleRoute = async (item, req, res) => {
95
+ const handleRoute = async (item, req, res, path) => {
96
96
  const handlerOptions = item.handler.options;
97
97
  const handlerMethod = handlerOptions.requestMethod || 'POST';
98
98
  const isWS = handlerMethod === 'WS';
99
99
  const url = `${appUrl}${// 结构:/test/sss?x=2
100
- isWS ? res.url : req.url}`;
100
+ path != null ? path : isWS ? res.url : req.url}`;
101
101
 
102
102
  if (isWS) {
103
103
  await item.handler.handle(undefined, {
@@ -178,7 +178,7 @@ class Server {
178
178
  throw new _http_error.HttpError.NotFound();
179
179
  }
180
180
 
181
- return handleRoute(routeMap[requestPath], req, res);
181
+ return handleRoute(routeMap[requestPath], req, res, requestPath);
182
182
  }
183
183
  });
184
184
  }
@@ -27,7 +27,7 @@ class CacheService {
27
27
  *
28
28
  * @param key 键
29
29
  * @param value 值
30
- * @param ttl 缓存时间(单位:时)
30
+ * @param ttl 缓存时间
31
31
  * @returns 返回设置的缓存内容
32
32
  */
33
33
 
@@ -36,8 +36,12 @@ class CacheService {
36
36
  const redisKey = this.toRedisKey(key);
37
37
  const redisValue = JSON.stringify(value);
38
38
  const redisTtl = typeof ttl === 'function' ? ttl(value, this.options.ttl) : ttl;
39
- await _x.x.redis.set(redisKey, redisValue, // 毫秒
40
- 'PX', (0, _date.ms)(redisTtl));
39
+
40
+ if (redisTtl) {
41
+ await _x.x.redis.set(redisKey, redisValue, // 毫秒
42
+ 'PX', (0, _date.ms)(redisTtl));
43
+ }
44
+
41
45
  return value;
42
46
  }
43
47
  /**
@@ -100,7 +104,7 @@ class CacheService {
100
104
  *
101
105
  * @param key 键
102
106
  * @param action 获取缓存内容的操作
103
- * @param ttl 缓存时间(单位:时)
107
+ * @param ttl 缓存时间
104
108
  * @returns 返回获取到的内容
105
109
  */
106
110
 
@@ -77,12 +77,12 @@ export class Server {
77
77
  const appUrl = x.env.APP_URL.replace(/\/+$/, '');
78
78
  const routeMap = keyBy(this.routes, item => item.path);
79
79
 
80
- const handleRoute = async (item, req, res) => {
80
+ const handleRoute = async (item, req, res, path) => {
81
81
  const handlerOptions = item.handler.options;
82
82
  const handlerMethod = handlerOptions.requestMethod || 'POST';
83
83
  const isWS = handlerMethod === 'WS';
84
84
  const url = `${appUrl}${// 结构:/test/sss?x=2
85
- isWS ? res.url : req.url}`;
85
+ path != null ? path : isWS ? res.url : req.url}`;
86
86
 
87
87
  if (isWS) {
88
88
  await item.handler.handle(undefined, {
@@ -163,7 +163,7 @@ export class Server {
163
163
  throw new HttpError.NotFound();
164
164
  }
165
165
 
166
- return handleRoute(routeMap[requestPath], req, res);
166
+ return handleRoute(routeMap[requestPath], req, res, requestPath);
167
167
  }
168
168
  });
169
169
  }
@@ -27,7 +27,7 @@ export declare class CacheService<TData extends Data = Data, TKey extends Key<TD
27
27
  *
28
28
  * @param key 键
29
29
  * @param value 值
30
- * @param ttl 缓存时间(单位:时)
30
+ * @param ttl 缓存时间
31
31
  * @returns 返回设置的缓存内容
32
32
  */
33
33
  set<K extends TKeyPath, V extends Value<TData, K>>(key: K, value: V, ttl?: MsValue | ((data: V, defaultTTL: MsValue) => MsValue)): Promise<V>;
@@ -57,7 +57,7 @@ export declare class CacheService<TData extends Data = Data, TKey extends Key<TD
57
57
  *
58
58
  * @param key 键
59
59
  * @param action 获取缓存内容的操作
60
- * @param ttl 缓存时间(单位:时)
60
+ * @param ttl 缓存时间
61
61
  * @returns 返回获取到的内容
62
62
  */
63
63
  remember<K extends TKeyPath, V extends Value<TData, K>>(key: K, action: () => V | Promise<V>, ttl?: MsValue | ((data: V, defaultTTL: MsValue) => MsValue)): Promise<V>;
@@ -17,7 +17,7 @@ export class CacheService {
17
17
  *
18
18
  * @param key 键
19
19
  * @param value 值
20
- * @param ttl 缓存时间(单位:时)
20
+ * @param ttl 缓存时间
21
21
  * @returns 返回设置的缓存内容
22
22
  */
23
23
 
@@ -26,8 +26,12 @@ export class CacheService {
26
26
  const redisKey = this.toRedisKey(key);
27
27
  const redisValue = JSON.stringify(value);
28
28
  const redisTtl = typeof ttl === 'function' ? ttl(value, this.options.ttl) : ttl;
29
- await x.redis.set(redisKey, redisValue, // 毫秒
30
- 'PX', ms(redisTtl));
29
+
30
+ if (redisTtl) {
31
+ await x.redis.set(redisKey, redisValue, // 毫秒
32
+ 'PX', ms(redisTtl));
33
+ }
34
+
31
35
  return value;
32
36
  }
33
37
  /**
@@ -90,7 +94,7 @@ export class CacheService {
90
94
  *
91
95
  * @param key 键
92
96
  * @param action 获取缓存内容的操作
93
- * @param ttl 缓存时间(单位:时)
97
+ * @param ttl 缓存时间
94
98
  * @returns 返回获取到的内容
95
99
  */
96
100
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.34.4",
3
+ "version": "1.34.6",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",