@art-ws/fastify-http-server 2.0.19 → 2.0.20
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.
@@ -10,7 +10,10 @@ export declare function createHttpServer({ routes, port, handlers, plugins, onWe
|
|
10
10
|
handlers?: {
|
11
11
|
errorHandler?: boolean;
|
12
12
|
notFoundHandler?: boolean;
|
13
|
-
preHandler: (
|
13
|
+
preHandler: (o?: {
|
14
|
+
context: HttpContext;
|
15
|
+
route: unknown;
|
16
|
+
}) => Promise<void>;
|
14
17
|
};
|
15
18
|
plugins?: {
|
16
19
|
formbody?: boolean;
|
@@ -58,12 +58,13 @@ export async function createHttpServer({ routes, port, handlers, plugins, onWebs
|
|
58
58
|
if (plugins?.cors) {
|
59
59
|
await fastify.register(cors);
|
60
60
|
}
|
61
|
-
routes.forEach((
|
61
|
+
routes.forEach((route) => {
|
62
|
+
const { method, path, handler, options } = route;
|
62
63
|
async function fastifyHandler(req, res) {
|
63
64
|
const req_id = req.headers["x-req-id"] ||
|
64
65
|
req.headers["x-request-id"] ||
|
65
66
|
req.id ||
|
66
|
-
"req-" + Date.now();
|
67
|
+
"req-" + Date.now() + "-" + Math.random().toString(36).substring(2, 8);
|
67
68
|
req.id = req_id;
|
68
69
|
let resolveFunc;
|
69
70
|
const promise = new Promise((resolve) => {
|
@@ -72,7 +73,7 @@ export async function createHttpServer({ routes, port, handlers, plugins, onWebs
|
|
72
73
|
const context = new FastifyHttpContext(promise, new FastifyHttpReq(req), new FastifyHttpRes(res), new FastifyHttpServer(fastify));
|
73
74
|
const result = await getRootInjector().runScope(async () => {
|
74
75
|
if (handlers?.preHandler) {
|
75
|
-
await handlers.preHandler(context);
|
76
|
+
await handlers.preHandler({ context, route });
|
76
77
|
}
|
77
78
|
return handler(context);
|
78
79
|
}, {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@art-ws/fastify-http-server",
|
3
|
-
"version": "2.0.
|
3
|
+
"version": "2.0.20",
|
4
4
|
"description": "Fastify Http server",
|
5
5
|
"license": "UNLICENSED",
|
6
6
|
"author": "Alexander Shagin",
|
@@ -18,8 +18,8 @@
|
|
18
18
|
"@fastify/websocket": "^11.2.0",
|
19
19
|
"fastify": "^5.5.0",
|
20
20
|
"fastify-multer": "^2.0.3",
|
21
|
-
"@art-ws/http-server": "2.0.
|
22
|
-
"@art-ws/di": "2.0.
|
21
|
+
"@art-ws/http-server": "2.0.17",
|
22
|
+
"@art-ws/di": "2.0.24"
|
23
23
|
},
|
24
24
|
"devDependencies": {
|
25
25
|
"eslint": "^9.34.0",
|