@art-ws/fastify-http-server 2.0.8 → 2.0.9
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.
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Injector } from "@art-ws/di";
|
2
|
-
import { CONTEXT, REQUEST, RESPONSE, } from "@art-ws/http-server";
|
2
|
+
import { CONTEXT, REQUEST, REQUEST_ID, RESPONSE, } from "@art-ws/http-server";
|
3
3
|
import cors from "@fastify/cors";
|
4
4
|
import formbody from "@fastify/formbody";
|
5
5
|
import multipart from "@fastify/multipart";
|
@@ -51,14 +51,20 @@ export async function createHttpServer({ routes, port, handlers, plugins, onPlug
|
|
51
51
|
req.id ||
|
52
52
|
"req-" + Date.now();
|
53
53
|
req.id = req_id;
|
54
|
-
|
54
|
+
let resolveFunc;
|
55
|
+
const promise = new Promise((resolve) => {
|
56
|
+
resolveFunc = resolve;
|
57
|
+
});
|
58
|
+
const context = new FastifyHttpContext(promise, new FastifyHttpReq(req), new FastifyHttpRes(res), new FastifyHttpServer(fastify));
|
55
59
|
const result = await Injector.root.runScope(() => handler(context), {
|
56
60
|
onEnd: () => {
|
57
61
|
res.headers({
|
58
62
|
"x-req-id": req_id,
|
59
63
|
});
|
64
|
+
resolveFunc({ context });
|
60
65
|
},
|
61
66
|
providers: [
|
67
|
+
{ token: REQUEST_ID, factory: () => req_id },
|
62
68
|
{ token: REQUEST, factory: () => req },
|
63
69
|
{ token: RESPONSE, factory: () => res },
|
64
70
|
{ token: CONTEXT, factory: () => context },
|
@@ -122,10 +128,12 @@ class FastifyHttpServer {
|
|
122
128
|
}
|
123
129
|
}
|
124
130
|
class FastifyHttpContext {
|
131
|
+
promise;
|
125
132
|
req;
|
126
133
|
res;
|
127
134
|
server;
|
128
|
-
constructor(req, res, server) {
|
135
|
+
constructor(promise, req, res, server) {
|
136
|
+
this.promise = promise;
|
129
137
|
this.req = req;
|
130
138
|
this.res = res;
|
131
139
|
this.server = server;
|
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.9",
|
4
4
|
"description": "Fastify Http server",
|
5
5
|
"license": "UNLICENSED",
|
6
6
|
"author": "Alexander Shagin",
|
@@ -16,8 +16,8 @@
|
|
16
16
|
"@fastify/multipart": "^9.0.3",
|
17
17
|
"@fastify/static": "^8.2.0",
|
18
18
|
"fastify": "^5.5.0",
|
19
|
-
"@art-ws/di": "2.0.
|
20
|
-
"@art-ws/http-server": "2.0.
|
19
|
+
"@art-ws/di": "2.0.10",
|
20
|
+
"@art-ws/http-server": "2.0.6"
|
21
21
|
},
|
22
22
|
"devDependencies": {
|
23
23
|
"eslint": "^9.34.0",
|