@art-ws/fastify-http-server 2.0.8 → 2.0.10

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
- const context = new FastifyHttpContext(new FastifyHttpReq(req), new FastifyHttpRes(res), new FastifyHttpServer(fastify));
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.8",
3
+ "version": "2.0.10",
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.7",
20
- "@art-ws/http-server": "2.0.5"
19
+ "@art-ws/di": "2.0.11",
20
+ "@art-ws/http-server": "2.0.7"
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-eslint": "2.0.3",
27
- "@art-ws/config-ts": "2.0.6"
26
+ "@art-ws/config-ts": "2.0.6",
27
+ "@art-ws/config-eslint": "2.0.3"
28
28
  },
29
29
  "scripts": {
30
30
  "build": "tsc",