@athenna/http 3.1.2 → 3.2.1
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.
|
@@ -34,8 +34,4 @@ export declare class FastifyHandler {
|
|
|
34
34
|
* Parse the fastify onError hook to an Athenna error handler.
|
|
35
35
|
*/
|
|
36
36
|
static error(handler: ErrorHandler): (error: any, req: FastifyRequest, res: FastifyReply) => Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Set the data object in th
|
|
39
|
-
*/
|
|
40
|
-
private static setData;
|
|
41
37
|
}
|
|
@@ -18,7 +18,9 @@ export class FastifyHandler {
|
|
|
18
18
|
return async (req, res) => {
|
|
19
19
|
const request = new Request(req);
|
|
20
20
|
const response = new Response(res);
|
|
21
|
-
|
|
21
|
+
if (!req.data) {
|
|
22
|
+
req.data = {};
|
|
23
|
+
}
|
|
22
24
|
await handler({
|
|
23
25
|
request,
|
|
24
26
|
response,
|
|
@@ -43,24 +45,24 @@ export class FastifyHandler {
|
|
|
43
45
|
return async (req, res, payload) => {
|
|
44
46
|
const request = new Request(req);
|
|
45
47
|
const response = new Response(res);
|
|
46
|
-
this.setData(req);
|
|
47
48
|
if (Is.Json(payload)) {
|
|
48
49
|
payload = JSON.parse(payload);
|
|
49
50
|
}
|
|
51
|
+
res.body = payload;
|
|
50
52
|
payload = await handler({
|
|
51
53
|
request,
|
|
52
54
|
response,
|
|
53
55
|
status: response.statusCode,
|
|
54
56
|
data: req.data,
|
|
55
|
-
body:
|
|
57
|
+
body: res.body,
|
|
56
58
|
params: req.params,
|
|
57
59
|
queries: req.query,
|
|
58
60
|
headers: req.headers,
|
|
59
61
|
});
|
|
62
|
+
res.body = payload;
|
|
60
63
|
if (Is.Object(payload)) {
|
|
61
64
|
payload = JSON.stringify(payload);
|
|
62
65
|
}
|
|
63
|
-
res.body = payload;
|
|
64
66
|
return payload;
|
|
65
67
|
};
|
|
66
68
|
}
|
|
@@ -71,7 +73,6 @@ export class FastifyHandler {
|
|
|
71
73
|
return async (req, res) => {
|
|
72
74
|
const request = new Request(req);
|
|
73
75
|
const response = new Response(res);
|
|
74
|
-
this.setData(req);
|
|
75
76
|
await handler({
|
|
76
77
|
request,
|
|
77
78
|
response,
|
|
@@ -92,7 +93,6 @@ export class FastifyHandler {
|
|
|
92
93
|
return async (error, req, res) => {
|
|
93
94
|
const request = new Request(req);
|
|
94
95
|
const response = new Response(res);
|
|
95
|
-
this.setData(req);
|
|
96
96
|
await handler({
|
|
97
97
|
request,
|
|
98
98
|
response,
|
|
@@ -105,13 +105,4 @@ export class FastifyHandler {
|
|
|
105
105
|
});
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Set the data object in th
|
|
110
|
-
*/
|
|
111
|
-
static setData(request) {
|
|
112
|
-
if (request.data) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
request.data = {};
|
|
116
|
-
}
|
|
117
108
|
}
|
|
@@ -21,6 +21,8 @@ export class ServerImpl {
|
|
|
21
21
|
constructor(options) {
|
|
22
22
|
this.fastify = fastify.fastify(options);
|
|
23
23
|
this.isListening = false;
|
|
24
|
+
this.fastify.decorateReply('body', null);
|
|
25
|
+
this.fastify.decorateRequest('data', null);
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* Get the representation of the internal radix tree used by the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/http",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "The Athenna Http server. Built on top of fastify.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "João Lenon <lenon@athenna.io>",
|
|
@@ -63,12 +63,12 @@
|
|
|
63
63
|
"fastify": "^4.13.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@athenna/artisan": "^3.
|
|
66
|
+
"@athenna/artisan": "^3.2.0",
|
|
67
67
|
"@athenna/common": "^3.3.1",
|
|
68
68
|
"@athenna/config": "^3.2.0",
|
|
69
69
|
"@athenna/ioc": "^3.1.5",
|
|
70
70
|
"@athenna/logger": "^3.1.5",
|
|
71
|
-
"@athenna/test": "^3.
|
|
71
|
+
"@athenna/test": "^3.2.0",
|
|
72
72
|
"@athenna/view": "^3.0.3",
|
|
73
73
|
"@fastify/cors": "^8.1.1",
|
|
74
74
|
"@fastify/helmet": "^10.0.2",
|