@art-ws/fastify-http-server 2.0.12 → 2.0.14
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,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { getRootInjector } from "@art-ws/di";
|
2
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";
|
@@ -56,12 +56,14 @@ export async function createHttpServer({ routes, port, handlers, plugins, onPlug
|
|
56
56
|
resolveFunc = resolve;
|
57
57
|
});
|
58
58
|
const context = new FastifyHttpContext(promise, new FastifyHttpReq(req), new FastifyHttpRes(res), new FastifyHttpServer(fastify));
|
59
|
-
const result = await
|
60
|
-
onEnd: () => {
|
59
|
+
const result = await getRootInjector().runScope(() => handler(context), {
|
60
|
+
onEnd: ({ injector }) => {
|
61
61
|
res.headers({
|
62
62
|
"x-req-id": req_id,
|
63
63
|
});
|
64
64
|
resolveFunc({ context });
|
65
|
+
disposeInstances(injector.getInstances());
|
66
|
+
injector.dispose();
|
65
67
|
},
|
66
68
|
providers: [
|
67
69
|
{ token: REQUEST_ID, factory: () => req_id },
|
@@ -139,3 +141,16 @@ class FastifyHttpContext {
|
|
139
141
|
this.server = server;
|
140
142
|
}
|
141
143
|
}
|
144
|
+
function disposeInstances(instances) {
|
145
|
+
for (const instance of instances) {
|
146
|
+
const d = instance;
|
147
|
+
if (d && typeof d.dispose === "function") {
|
148
|
+
try {
|
149
|
+
d.dispose();
|
150
|
+
}
|
151
|
+
catch (error) {
|
152
|
+
console.error("Error disposing instance:", error);
|
153
|
+
}
|
154
|
+
}
|
155
|
+
}
|
156
|
+
}
|
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.14",
|
4
4
|
"description": "Fastify Http server",
|
5
5
|
"license": "UNLICENSED",
|
6
6
|
"author": "Alexander Shagin",
|
@@ -16,15 +16,15 @@
|
|
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.19",
|
20
|
+
"@art-ws/http-server": "2.0.11"
|
21
21
|
},
|
22
22
|
"devDependencies": {
|
23
23
|
"eslint": "^9.34.0",
|
24
24
|
"typescript": "^5.9.2",
|
25
25
|
"vitest": "^3.2.4",
|
26
|
-
"@art-ws/config-
|
27
|
-
"@art-ws/config-
|
26
|
+
"@art-ws/config-eslint": "2.0.3",
|
27
|
+
"@art-ws/config-ts": "2.0.6"
|
28
28
|
},
|
29
29
|
"scripts": {
|
30
30
|
"build": "tsc",
|