@jayfong/x-utils 1.0.0-202408290922 → 1.0.0-202408290944

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.
@@ -47,8 +47,16 @@ class XHttpServer {
47
47
  secret: "cm0elm25o000094rlctgk6a7w"
48
48
  });
49
49
  Object.keys(this.options.handlers).forEach((name) => {
50
- fastify.post(
51
- `/${name}`,
50
+ let _method;
51
+ let _name;
52
+ if (name.includes("#")) {
53
+ [_method, _name] = name.split("#");
54
+ } else {
55
+ _method = "post";
56
+ _name = name;
57
+ }
58
+ fastify[_method](
59
+ `/${_name}`,
52
60
  (req, rep) => this.options.handlers[name](req.body, req, rep)
53
61
  );
54
62
  });
package/http_server.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { FastifyReply, FastifyRequest } from 'fastify';
2
2
  export type XHttpServerOptions = {
3
+ /** 监听端口 */
3
4
  port: number;
5
+ /** key 为处理器名称,可以加请求方法前缀,如 get#, put# 等,不加则默认 post */
4
6
  handlers: Record<string, (data: any, req: FastifyRequest, rep: FastifyReply) => any>;
5
7
  };
6
8
  export declare class XHttpServer {
package/http_server.js CHANGED
@@ -14,8 +14,16 @@ class XHttpServer {
14
14
  secret: "cm0elm25o000094rlctgk6a7w"
15
15
  });
16
16
  Object.keys(this.options.handlers).forEach((name) => {
17
- fastify.post(
18
- `/${name}`,
17
+ let _method;
18
+ let _name;
19
+ if (name.includes("#")) {
20
+ [_method, _name] = name.split("#");
21
+ } else {
22
+ _method = "post";
23
+ _name = name;
24
+ }
25
+ fastify[_method](
26
+ `/${_name}`,
19
27
  (req, rep) => this.options.handlers[name](req.body, req, rep)
20
28
  );
21
29
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jayfong/x-utils",
3
3
  "description": "123456",
4
- "version": "1.0.0-202408290922",
4
+ "version": "1.0.0-202408290944",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "vtils": "^4.115.0",