@art-ws/fastify-http-server 2.0.4 → 2.0.5
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.
@@ -11,6 +11,10 @@ export declare function createHttpServer({ routes, port, handlers, plugins, onPl
|
|
11
11
|
formbody?: boolean;
|
12
12
|
multipart?: boolean;
|
13
13
|
cors?: boolean;
|
14
|
+
static?: {
|
15
|
+
root: string;
|
16
|
+
wildcard?: boolean;
|
17
|
+
};
|
14
18
|
};
|
15
19
|
onPlugin?: (options: {
|
16
20
|
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.
|
3
|
+
"version": "2.0.5",
|
4
4
|
"description": "Fastify Http server",
|
5
5
|
"license": "UNLICENSED",
|
6
6
|
"author": "Alexander Shagin",
|
@@ -14,6 +14,7 @@
|
|
14
14
|
"@fastify/cors": "11.0.1",
|
15
15
|
"@fastify/formbody": "8.0.2",
|
16
16
|
"@fastify/multipart": "9.0.3",
|
17
|
+
"@fastify/static": "8.2.0",
|
17
18
|
"fastify": "5.4.0",
|
18
19
|
"@art-ws/di": "2.0.2",
|
19
20
|
"@art-ws/http-server": "2.0.2"
|