@athenna/http 5.27.0 → 5.28.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/http",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.28.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>",
|
|
@@ -85,6 +85,7 @@
|
|
|
85
85
|
"@athenna/vite": "^5.13.0",
|
|
86
86
|
"@fastify/cors": "^10.0.2",
|
|
87
87
|
"@fastify/helmet": "^13.0.1",
|
|
88
|
+
"@fastify/multipart": "^9.0.3",
|
|
88
89
|
"@fastify/rate-limit": "^10.2.2",
|
|
89
90
|
"@fastify/static": "^8.0.4",
|
|
90
91
|
"@fastify/swagger": "^9.4.2",
|
package/src/context/Request.d.ts
CHANGED
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
+
import type { SavedMultipartFile, FastifyMultipartBaseOptions } from '@fastify/multipart';
|
|
9
10
|
import type { FastifyRequest } from 'fastify';
|
|
10
11
|
import { Macroable } from '@athenna/common';
|
|
12
|
+
import type { BusboyConfig } from '@fastify/busboy';
|
|
11
13
|
export declare class Request extends Macroable {
|
|
12
14
|
/**
|
|
13
15
|
* The fastify request object.
|
|
@@ -245,6 +247,41 @@ export declare class Request extends Macroable {
|
|
|
245
247
|
* ```
|
|
246
248
|
*/
|
|
247
249
|
except(keys: string[]): any;
|
|
250
|
+
/**
|
|
251
|
+
* Check if the request is multipart.
|
|
252
|
+
*/
|
|
253
|
+
isMultipart(): boolean;
|
|
254
|
+
/**
|
|
255
|
+
* Get the form data from the request.
|
|
256
|
+
*/
|
|
257
|
+
formData(): Promise<FormData>;
|
|
258
|
+
/**
|
|
259
|
+
* Get the parts from the request.
|
|
260
|
+
*/
|
|
261
|
+
parts(options?: Omit<BusboyConfig, 'headers'>): AsyncIterableIterator<import("@fastify/multipart").Multipart>;
|
|
262
|
+
/**
|
|
263
|
+
* Get the file from the request.
|
|
264
|
+
*/
|
|
265
|
+
file(options?: Omit<BusboyConfig, 'headers'> | FastifyMultipartBaseOptions): Promise<import("@fastify/multipart").MultipartFile>;
|
|
266
|
+
/**
|
|
267
|
+
* Get the files from the request.
|
|
268
|
+
*/
|
|
269
|
+
files(options?: Omit<BusboyConfig, 'headers'> | FastifyMultipartBaseOptions): AsyncIterableIterator<import("@fastify/multipart").MultipartFile>;
|
|
270
|
+
/**
|
|
271
|
+
* Save the files from the request.
|
|
272
|
+
*/
|
|
273
|
+
saveRequestFiles(options?: Omit<BusboyConfig, 'headers'> & {
|
|
274
|
+
tmpdir?: string;
|
|
275
|
+
}): Promise<SavedMultipartFile[]>;
|
|
276
|
+
/**
|
|
277
|
+
* Clean the files from the request.
|
|
278
|
+
*/
|
|
279
|
+
cleanRequestFiles(): Promise<void>;
|
|
280
|
+
/**
|
|
281
|
+
* This will get populated as soon as a call to `saveRequestFiles` gets resolved.
|
|
282
|
+
* Avoiding any future duplicate work
|
|
283
|
+
*/
|
|
284
|
+
get savedRequestFiles(): SavedMultipartFile[] | null;
|
|
248
285
|
/**
|
|
249
286
|
* Get the original fastify request.
|
|
250
287
|
*/
|
package/src/context/Request.js
CHANGED
|
@@ -309,6 +309,55 @@ export class Request extends Macroable {
|
|
|
309
309
|
});
|
|
310
310
|
return body;
|
|
311
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Check if the request is multipart.
|
|
314
|
+
*/
|
|
315
|
+
isMultipart() {
|
|
316
|
+
return this.request.isMultipart();
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Get the form data from the request.
|
|
320
|
+
*/
|
|
321
|
+
formData() {
|
|
322
|
+
return this.request.formData();
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Get the parts from the request.
|
|
326
|
+
*/
|
|
327
|
+
parts(options) {
|
|
328
|
+
return this.request.parts(options);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Get the file from the request.
|
|
332
|
+
*/
|
|
333
|
+
file(options) {
|
|
334
|
+
return this.request.file(options);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Get the files from the request.
|
|
338
|
+
*/
|
|
339
|
+
files(options) {
|
|
340
|
+
return this.request.files(options);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Save the files from the request.
|
|
344
|
+
*/
|
|
345
|
+
saveRequestFiles(options) {
|
|
346
|
+
return this.request.saveRequestFiles(options);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Clean the files from the request.
|
|
350
|
+
*/
|
|
351
|
+
cleanRequestFiles() {
|
|
352
|
+
return this.request.cleanRequestFiles();
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* This will get populated as soon as a call to `saveRequestFiles` gets resolved.
|
|
356
|
+
* Avoiding any future duplicate work
|
|
357
|
+
*/
|
|
358
|
+
get savedRequestFiles() {
|
|
359
|
+
return this.request.savedRequestFiles;
|
|
360
|
+
}
|
|
312
361
|
/**
|
|
313
362
|
* Get the original fastify request.
|
|
314
363
|
*/
|
|
@@ -36,6 +36,10 @@ export declare class HttpKernel {
|
|
|
36
36
|
* Register the @athenna/vite plugin in the Http server.
|
|
37
37
|
*/
|
|
38
38
|
registerVite(trace?: boolean): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Register the @fastify/multipart plugin in the Http server.
|
|
41
|
+
*/
|
|
42
|
+
registerMultipart(): Promise<void>;
|
|
39
43
|
/**
|
|
40
44
|
* Register the global log terminator in the Http server.
|
|
41
45
|
*/
|
|
@@ -15,19 +15,12 @@ import { sep, isAbsolute, resolve } from 'node:path';
|
|
|
15
15
|
import { Annotation } from '@athenna/ioc';
|
|
16
16
|
import { File, Path, Module, String } from '@athenna/common';
|
|
17
17
|
import { HttpExceptionHandler } from '#src/handlers/HttpExceptionHandler';
|
|
18
|
-
const corsPlugin = await Module.safeImport('@fastify/cors');
|
|
19
|
-
const helmetPlugin = await Module.safeImport('@fastify/helmet');
|
|
20
|
-
const swaggerPlugin = await Module.safeImport('@fastify/swagger');
|
|
21
|
-
const swaggerUiPlugin = await Module.safeImport('@fastify/swagger-ui');
|
|
22
|
-
const rateLimitPlugin = await Module.safeImport('@fastify/rate-limit');
|
|
23
|
-
const staticPlugin = await Module.safeImport('@fastify/static');
|
|
24
|
-
const rTracerPlugin = await Module.safeImport('cls-rtracer');
|
|
25
|
-
const vitePlugin = await Module.safeImport('@athenna/vite/plugins/fastify');
|
|
26
18
|
export class HttpKernel {
|
|
27
19
|
/**
|
|
28
20
|
* Register the @fastify/cors plugin in the Http server.
|
|
29
21
|
*/
|
|
30
22
|
async registerCors() {
|
|
23
|
+
const corsPlugin = await Module.safeImport('@fastify/cors');
|
|
31
24
|
if (Config.is('http.cors.enabled', false)) {
|
|
32
25
|
debug('Not able to register cors plugin. Set the http.cors.enabled configuration as true.');
|
|
33
26
|
return;
|
|
@@ -42,6 +35,7 @@ export class HttpKernel {
|
|
|
42
35
|
* Register the @fastify/helmet plugin in the Http server.
|
|
43
36
|
*/
|
|
44
37
|
async registerHelmet() {
|
|
38
|
+
const helmetPlugin = await Module.safeImport('@fastify/helmet');
|
|
45
39
|
if (Config.is('http.helmet.enabled', false)) {
|
|
46
40
|
debug('Not able to register helmet plugin. Set the http.helmet.enabled configuration as true.');
|
|
47
41
|
return;
|
|
@@ -56,6 +50,8 @@ export class HttpKernel {
|
|
|
56
50
|
* Register the @fastify/swagger plugin in the Http server.
|
|
57
51
|
*/
|
|
58
52
|
async registerSwagger() {
|
|
53
|
+
const swaggerPlugin = await Module.safeImport('@fastify/swagger');
|
|
54
|
+
const swaggerUiPlugin = await Module.safeImport('@fastify/swagger-ui');
|
|
59
55
|
if (Config.is('http.swagger.enabled', false)) {
|
|
60
56
|
debug('Not able to register swagger plugin. Set the http.swagger.enabled configuration as true.');
|
|
61
57
|
return;
|
|
@@ -86,6 +82,7 @@ export class HttpKernel {
|
|
|
86
82
|
* Register the @fastify/rate-limit plugin in the Http server.
|
|
87
83
|
*/
|
|
88
84
|
async registerRateLimit() {
|
|
85
|
+
const rateLimitPlugin = await Module.safeImport('@fastify/rate-limit');
|
|
89
86
|
if (Config.is('http.rateLimit.enabled', false)) {
|
|
90
87
|
debug('Not able to register rate limit plugin. Set the http.rateLimit.enabled configuration as true.');
|
|
91
88
|
return;
|
|
@@ -100,6 +97,7 @@ export class HttpKernel {
|
|
|
100
97
|
* Register the @fastify/static plugin in the Http server.
|
|
101
98
|
*/
|
|
102
99
|
async registerStatic() {
|
|
100
|
+
const staticPlugin = await Module.safeImport('@fastify/static');
|
|
103
101
|
if (Config.is('http.static.enabled', false)) {
|
|
104
102
|
debug('Not able to register static plugin. Set the http.static.enabled configuration as true.');
|
|
105
103
|
return;
|
|
@@ -114,6 +112,7 @@ export class HttpKernel {
|
|
|
114
112
|
* Register the cls-rtracer plugin in the Http server.
|
|
115
113
|
*/
|
|
116
114
|
async registerRTracer(trace) {
|
|
115
|
+
const rTracerPlugin = await Module.safeImport('cls-rtracer');
|
|
117
116
|
if (trace === false) {
|
|
118
117
|
debug('Not able to register rTracer plugin. Set the trace option as true in your http server options.');
|
|
119
118
|
return;
|
|
@@ -133,6 +132,7 @@ export class HttpKernel {
|
|
|
133
132
|
* Register the @athenna/vite plugin in the Http server.
|
|
134
133
|
*/
|
|
135
134
|
async registerVite(trace) {
|
|
135
|
+
const vitePlugin = await Module.safeImport('@athenna/vite/plugins/fastify');
|
|
136
136
|
if (trace === false) {
|
|
137
137
|
debug('Not able to register vite plugin. Set the trace option as true in your http server options.');
|
|
138
138
|
return;
|
|
@@ -147,6 +147,21 @@ export class HttpKernel {
|
|
|
147
147
|
}
|
|
148
148
|
await Server.plugin(vitePlugin, this.getConfig('http.vite'));
|
|
149
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Register the @fastify/multipart plugin in the Http server.
|
|
152
|
+
*/
|
|
153
|
+
async registerMultipart() {
|
|
154
|
+
const multipartPlugin = await Module.safeImport('@fastify/multipart');
|
|
155
|
+
if (Config.is('http.multipart.enabled', false)) {
|
|
156
|
+
debug('Not able to register multipart plugin. Set the http.multipart.enabled configuration as true.');
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (!multipartPlugin) {
|
|
160
|
+
debug('Not able to register multipart plugin. Install @fastify/multipart package.');
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
await Server.plugin(multipartPlugin, this.getConfig('http.multipart'));
|
|
164
|
+
}
|
|
150
165
|
/**
|
|
151
166
|
* Register the global log terminator in the Http server.
|
|
152
167
|
*/
|