@jayfong/x-utils 1.0.0-202408101439 → 1.0.0-202408290928
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/_cjs/http_server.js +16 -1
- package/http_server.d.ts +4 -1
- package/http_server.js +16 -1
- package/package.json +2 -1
package/_cjs/http_server.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(http_server_exports, {
|
|
|
31
31
|
XHttpServer: () => XHttpServer
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(http_server_exports);
|
|
34
|
+
var import_cookie = __toESM(require("@fastify/cookie"), 1);
|
|
34
35
|
var import_cors = __toESM(require("@fastify/cors"), 1);
|
|
35
36
|
var import_fastify = __toESM(require("fastify"), 1);
|
|
36
37
|
class XHttpServer {
|
|
@@ -42,8 +43,22 @@ class XHttpServer {
|
|
|
42
43
|
logger: true
|
|
43
44
|
});
|
|
44
45
|
await fastify.register(import_cors.default);
|
|
46
|
+
await fastify.register(import_cookie.default, {
|
|
47
|
+
secret: "cm0elm25o000094rlctgk6a7w"
|
|
48
|
+
});
|
|
45
49
|
Object.keys(this.options.handlers).forEach((name) => {
|
|
46
|
-
|
|
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}`,
|
|
60
|
+
(req, rep) => this.options.handlers[name](req.body, req, rep)
|
|
61
|
+
);
|
|
47
62
|
});
|
|
48
63
|
await fastify.listen({
|
|
49
64
|
host: "0.0.0.0",
|
package/http_server.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { FastifyReply, FastifyRequest } from 'fastify';
|
|
1
2
|
export type XHttpServerOptions = {
|
|
3
|
+
/** 监听端口 */
|
|
2
4
|
port: number;
|
|
3
|
-
|
|
5
|
+
/** key 为处理器名称,可以加请求方法前缀,如 get#, put# 等,不加则默认 post */
|
|
6
|
+
handlers: Record<string, (data: any, req: FastifyRequest, rep: FastifyReply) => any>;
|
|
4
7
|
};
|
|
5
8
|
export declare class XHttpServer {
|
|
6
9
|
private options;
|
package/http_server.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import cookie from "@fastify/cookie";
|
|
1
2
|
import cors from "@fastify/cors";
|
|
2
3
|
import Fastify from "fastify";
|
|
3
4
|
class XHttpServer {
|
|
@@ -9,8 +10,22 @@ class XHttpServer {
|
|
|
9
10
|
logger: true
|
|
10
11
|
});
|
|
11
12
|
await fastify.register(cors);
|
|
13
|
+
await fastify.register(cookie, {
|
|
14
|
+
secret: "cm0elm25o000094rlctgk6a7w"
|
|
15
|
+
});
|
|
12
16
|
Object.keys(this.options.handlers).forEach((name) => {
|
|
13
|
-
|
|
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}`,
|
|
27
|
+
(req, rep) => this.options.handlers[name](req.body, req, rep)
|
|
28
|
+
);
|
|
14
29
|
});
|
|
15
30
|
await fastify.listen({
|
|
16
31
|
host: "0.0.0.0",
|
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-
|
|
4
|
+
"version": "1.0.0-202408290928",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"vtils": "^4.115.0",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"@types/probe-image-size": "^7.2.5",
|
|
23
23
|
"docx": "^8.5.0",
|
|
24
24
|
"image-dimensions": "^2.3.0",
|
|
25
|
+
"@fastify/cookie": "^9.4.0",
|
|
25
26
|
"@fastify/cors": "^9.0.1",
|
|
26
27
|
"fastify": "^4.26.0",
|
|
27
28
|
"nzh": "^1.0.12",
|