@art-ws/fastify-http-server 2.0.4 → 2.0.6

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,6 @@
1
1
  import { type RouteDef } from "@art-ws/http-server";
2
2
  import { type FastifyInstance, type FastifyReply, type FastifyRequest } from "fastify";
3
+ export type { FastifyInstance, FastifyReply, FastifyRequest };
3
4
  export declare function createHttpServer({ routes, port, handlers, plugins, onPlugin, }: {
4
5
  routes: RouteDef<FastifyRequest, FastifyReply, FastifyInstance>[];
5
6
  port?: number;
@@ -11,6 +12,10 @@ export declare function createHttpServer({ routes, port, handlers, plugins, onPl
11
12
  formbody?: boolean;
12
13
  multipart?: boolean;
13
14
  cors?: boolean;
15
+ static?: {
16
+ root: string;
17
+ wildcard?: boolean;
18
+ };
14
19
  };
15
20
  onPlugin?: (options: {
16
21
  fastify: FastifyInstance;
@@ -3,6 +3,7 @@ import { CONTEXT, REQUEST, 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";
6
+ import fastifyStatic from "@fastify/static";
6
7
  import Fastify, {} from "fastify";
7
8
  export async function createHttpServer({ routes, port, handlers, plugins, onPlugin, }) {
8
9
  const fastify = Fastify({
@@ -20,6 +21,12 @@ export async function createHttpServer({ routes, port, handlers, plugins, onPlug
20
21
  });
21
22
  });
22
23
  }
24
+ if (plugins?.static?.root) {
25
+ fastify.register(fastifyStatic, {
26
+ root: plugins.static.root,
27
+ wildcard: !!plugins.static.wildcard,
28
+ });
29
+ }
23
30
  if (handlers?.notFoundHandler) {
24
31
  // https://fastify.dev/docs/latest/Reference/Server/#setnotfoundhandler
25
32
  fastify.setNotFoundHandler((_req, reply) => {
@@ -45,7 +52,7 @@ export async function createHttpServer({ routes, port, handlers, plugins, onPlug
45
52
  "req-" + Date.now();
46
53
  req.id = req_id;
47
54
  const context = new FastifyHttpContext(new FastifyHttpReq(req), new FastifyHttpRes(res), new FastifyHttpServer(fastify));
48
- const result = Injector.root.runScope(() => handler(context), {
55
+ const result = await Injector.root.runScope(() => handler(context), {
49
56
  onEnd: () => {
50
57
  res.headers({
51
58
  "x-req-id": req_id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@art-ws/fastify-http-server",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "Fastify Http server",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Alexander Shagin",
@@ -11,26 +11,28 @@
11
11
  "./dist/*"
12
12
  ],
13
13
  "dependencies": {
14
- "@fastify/cors": "11.0.1",
15
- "@fastify/formbody": "8.0.2",
16
- "@fastify/multipart": "9.0.3",
17
- "fastify": "5.4.0",
18
- "@art-ws/di": "2.0.2",
19
- "@art-ws/http-server": "2.0.2"
14
+ "@fastify/cors": "^11.1.0",
15
+ "@fastify/formbody": "^8.0.2",
16
+ "@fastify/multipart": "^9.0.3",
17
+ "@fastify/static": "^8.2.0",
18
+ "fastify": "^5.5.0",
19
+ "@art-ws/http-server": "2.0.3",
20
+ "@art-ws/di": "2.0.5"
20
21
  },
21
22
  "devDependencies": {
22
- "eslint": "9.29.0",
23
- "typescript": "5.6.2",
24
- "vitest": "3.2.4",
25
- "@art-ws/config-eslint": "2.0.2",
26
- "@art-ws/config-ts": "2.0.5"
23
+ "eslint": "^9.34.0",
24
+ "typescript": "^5.9.2",
25
+ "vitest": "^3.2.4",
26
+ "@art-ws/config-eslint": "2.0.3",
27
+ "@art-ws/config-ts": "2.0.6"
27
28
  },
28
29
  "scripts": {
29
30
  "build": "tsc",
31
+ "check": "pnpm clean && pnpm build && pnpm lint && pnpm test",
30
32
  "clean": "rm -rf dist",
31
33
  "clean:nm": "rm -rf node_modules",
32
34
  "lint": "eslint .",
33
- "pub": "pnpm prepare && pnpm version patch && pnpm publish --access public --no-git-checks",
35
+ "pub": "pnpm check && pnpm version patch && pnpm publish --access public --no-git-checks",
34
36
  "test": "exit 0",
35
37
  "test:watch": "vitest",
36
38
  "watch": "tsc --watch"