@athenna/http 3.1.1 → 3.2.0
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.
- package/build/Context/Request.d.ts +1 -1
- package/build/Context/Request.js +2 -2
- package/build/Context/Response.d.ts +4 -0
- package/build/Context/Response.js +7 -0
- package/build/Handlers/FastifyHandler.d.ts +0 -4
- package/build/Handlers/FastifyHandler.js +5 -16
- package/build/Server/ServerImpl.js +2 -0
- package/build/index.d.ts +3 -0
- package/package.json +8 -7
package/build/Context/Request.js
CHANGED
|
@@ -134,10 +134,10 @@ export class Request {
|
|
|
134
134
|
return this.getAddressInfo().port;
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
|
-
* Get the
|
|
137
|
+
* Get the http version.
|
|
138
138
|
*/
|
|
139
139
|
get version() {
|
|
140
|
-
return this.request.
|
|
140
|
+
return this.request.raw.httpVersion;
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
143
|
* Get a value from the request params or the default value.
|
|
@@ -20,6 +20,12 @@ export class Response {
|
|
|
20
20
|
get sent() {
|
|
21
21
|
return this.response.sent;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the response body sent in response.
|
|
25
|
+
*/
|
|
26
|
+
get body() {
|
|
27
|
+
return this.response.body;
|
|
28
|
+
}
|
|
23
29
|
/**
|
|
24
30
|
* Get the status code sent in response.
|
|
25
31
|
*/
|
|
@@ -43,6 +49,7 @@ export class Response {
|
|
|
43
49
|
*/
|
|
44
50
|
async send(data) {
|
|
45
51
|
await this.response.send(data);
|
|
52
|
+
this.response.body = data;
|
|
46
53
|
return this;
|
|
47
54
|
}
|
|
48
55
|
/**
|
|
@@ -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,6 @@ export class FastifyHandler {
|
|
|
18
18
|
return async (req, res) => {
|
|
19
19
|
const request = new Request(req);
|
|
20
20
|
const response = new Response(res);
|
|
21
|
-
this.setData(req);
|
|
22
21
|
await handler({
|
|
23
22
|
request,
|
|
24
23
|
response,
|
|
@@ -43,20 +42,21 @@ export class FastifyHandler {
|
|
|
43
42
|
return async (req, res, payload) => {
|
|
44
43
|
const request = new Request(req);
|
|
45
44
|
const response = new Response(res);
|
|
46
|
-
this.setData(req);
|
|
47
45
|
if (Is.Json(payload)) {
|
|
48
46
|
payload = JSON.parse(payload);
|
|
49
47
|
}
|
|
48
|
+
res.body = payload;
|
|
50
49
|
payload = await handler({
|
|
51
50
|
request,
|
|
52
51
|
response,
|
|
53
52
|
status: response.statusCode,
|
|
54
53
|
data: req.data,
|
|
55
|
-
body:
|
|
54
|
+
body: res.body,
|
|
56
55
|
params: req.params,
|
|
57
56
|
queries: req.query,
|
|
58
57
|
headers: req.headers,
|
|
59
58
|
});
|
|
59
|
+
res.body = payload;
|
|
60
60
|
if (Is.Object(payload)) {
|
|
61
61
|
payload = JSON.stringify(payload);
|
|
62
62
|
}
|
|
@@ -70,14 +70,13 @@ export class FastifyHandler {
|
|
|
70
70
|
return async (req, res) => {
|
|
71
71
|
const request = new Request(req);
|
|
72
72
|
const response = new Response(res);
|
|
73
|
-
this.setData(req);
|
|
74
73
|
await handler({
|
|
75
74
|
request,
|
|
76
75
|
response,
|
|
77
76
|
params: req.params,
|
|
78
77
|
queries: req.query,
|
|
79
78
|
data: req.data,
|
|
80
|
-
body: req.body,
|
|
79
|
+
body: res.body || req.body,
|
|
81
80
|
headers: res.getHeaders(),
|
|
82
81
|
status: res.statusCode,
|
|
83
82
|
responseTime: res.getResponseTime(),
|
|
@@ -91,12 +90,11 @@ export class FastifyHandler {
|
|
|
91
90
|
return async (error, req, res) => {
|
|
92
91
|
const request = new Request(req);
|
|
93
92
|
const response = new Response(res);
|
|
94
|
-
this.setData(req);
|
|
95
93
|
await handler({
|
|
96
94
|
request,
|
|
97
95
|
response,
|
|
98
96
|
data: req.data,
|
|
99
|
-
body: req.body,
|
|
97
|
+
body: res.body || req.body,
|
|
100
98
|
params: req.params,
|
|
101
99
|
queries: req.query,
|
|
102
100
|
headers: req.headers,
|
|
@@ -104,13 +102,4 @@ export class FastifyHandler {
|
|
|
104
102
|
});
|
|
105
103
|
};
|
|
106
104
|
}
|
|
107
|
-
/**
|
|
108
|
-
* Set the data object in th
|
|
109
|
-
*/
|
|
110
|
-
static setData(request) {
|
|
111
|
-
if (request.data) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
request.data = {};
|
|
115
|
-
}
|
|
116
105
|
}
|
|
@@ -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', {});
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* Get the representation of the internal radix tree used by the
|
package/build/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/http",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
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,13 @@
|
|
|
63
63
|
"fastify": "^4.13.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@athenna/artisan": "^3.
|
|
67
|
-
"@athenna/common": "^3.
|
|
68
|
-
"@athenna/config": "^3.
|
|
69
|
-
"@athenna/ioc": "^3.
|
|
70
|
-
"@athenna/logger": "^3.
|
|
71
|
-
"@athenna/
|
|
66
|
+
"@athenna/artisan": "^3.2.0",
|
|
67
|
+
"@athenna/common": "^3.3.1",
|
|
68
|
+
"@athenna/config": "^3.2.0",
|
|
69
|
+
"@athenna/ioc": "^3.1.5",
|
|
70
|
+
"@athenna/logger": "^3.1.5",
|
|
71
|
+
"@athenna/test": "^3.2.0",
|
|
72
|
+
"@athenna/view": "^3.0.3",
|
|
72
73
|
"@fastify/cors": "^8.1.1",
|
|
73
74
|
"@fastify/helmet": "^10.0.2",
|
|
74
75
|
"@fastify/rate-limit": "^7.5.0",
|