@athenna/http 1.2.4 → 1.2.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.
- package/package.json +3 -1
- package/src/Http.d.ts +17 -1
- package/src/Http.js +22 -0
- package/src/Router/Router.d.ts +1 -0
- package/src/Router/Router.js +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/http",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
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>",
|
|
@@ -163,6 +163,8 @@
|
|
|
163
163
|
"@athenna/logger": "1.1.7",
|
|
164
164
|
"@secjs/utils": "1.8.3",
|
|
165
165
|
"fastify": "3.27.4",
|
|
166
|
+
"fastify-cors": "6.0.3",
|
|
167
|
+
"fastify-rate-limit": "5.8.0",
|
|
166
168
|
"reflect-metadata": "0.1.13",
|
|
167
169
|
"tscpaths": "0.0.9"
|
|
168
170
|
}
|
package/src/Http.d.ts
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import LightMyRequest from 'light-my-request';
|
|
10
|
-
import {
|
|
10
|
+
import { FastifyCorsOptions } from 'fastify-cors';
|
|
11
|
+
import { RateLimitPluginOptions } from 'fastify-rate-limit';
|
|
12
|
+
import { FastifyInstance, FastifyPluginCallback, FastifyPluginOptions, FastifyRegisterOptions, InjectOptions, PrintRoutesOptions } from 'fastify';
|
|
11
13
|
import { HttpMethodTypes } from './Contracts/HttpMethodTypes';
|
|
12
14
|
import { HandlerContract } from './Contracts/Context/HandlerContract';
|
|
13
15
|
import { MiddlewareTypesContract } from './Contracts/MiddlewareTypesContract';
|
|
@@ -34,6 +36,20 @@ export declare class Http {
|
|
|
34
36
|
* @return Http
|
|
35
37
|
*/
|
|
36
38
|
setErrorHandler(handler: ErrorHandlerContract): void;
|
|
39
|
+
/**
|
|
40
|
+
* Register a new fastify plugin.
|
|
41
|
+
*
|
|
42
|
+
* @return FastifyInstance
|
|
43
|
+
*/
|
|
44
|
+
register(plugin: FastifyPluginCallback<FastifyPluginOptions>, opts?: FastifyRegisterOptions<FastifyPluginOptions>): void;
|
|
45
|
+
/**
|
|
46
|
+
* Register the cors plugin to fastify server.
|
|
47
|
+
*/
|
|
48
|
+
registerCors(opts?: FastifyCorsOptions): void;
|
|
49
|
+
/**
|
|
50
|
+
* Register the rateLimit plugin to fastify server.
|
|
51
|
+
*/
|
|
52
|
+
registerRateLimit(opts?: RateLimitPluginOptions): void;
|
|
37
53
|
/**
|
|
38
54
|
* Get the fastify server instance.
|
|
39
55
|
*
|
package/src/Http.js
CHANGED
|
@@ -12,6 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.Http = void 0;
|
|
15
|
+
const fastify_cors_1 = __importDefault(require("fastify-cors"));
|
|
16
|
+
const fastify_rate_limit_1 = __importDefault(require("fastify-rate-limit"));
|
|
15
17
|
const fastify_1 = __importDefault(require("fastify"));
|
|
16
18
|
const FastifyHandler_1 = require("./Handlers/FastifyHandler");
|
|
17
19
|
class Http {
|
|
@@ -32,6 +34,26 @@ class Http {
|
|
|
32
34
|
const fastifyErrorHandler = FastifyHandler_1.FastifyHandler.createErrorHandler(handler);
|
|
33
35
|
this.server.setErrorHandler(fastifyErrorHandler);
|
|
34
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Register a new fastify plugin.
|
|
39
|
+
*
|
|
40
|
+
* @return FastifyInstance
|
|
41
|
+
*/
|
|
42
|
+
register(plugin, opts) {
|
|
43
|
+
this.server.register(plugin, opts);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Register the cors plugin to fastify server.
|
|
47
|
+
*/
|
|
48
|
+
registerCors(opts) {
|
|
49
|
+
this.register(fastify_cors_1.default, opts);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Register the rateLimit plugin to fastify server.
|
|
53
|
+
*/
|
|
54
|
+
registerRateLimit(opts) {
|
|
55
|
+
this.register(fastify_rate_limit_1.default, opts);
|
|
56
|
+
}
|
|
35
57
|
/**
|
|
36
58
|
* Get the fastify server instance.
|
|
37
59
|
*
|
package/src/Router/Router.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare class Router {
|
|
|
24
24
|
route(url: string, methods: HttpMethodTypes[], handler: HandlerContract | string): Route;
|
|
25
25
|
group(callback: () => void): RouteGroup;
|
|
26
26
|
resource(resource: string, controller: any): RouteResource;
|
|
27
|
+
redirect(url: string, redirectTo: string, status?: number): Route;
|
|
27
28
|
get(url: string, handler: HandlerContract | string): Route;
|
|
28
29
|
head(url: string, handler: HandlerContract | string): Route;
|
|
29
30
|
post(url: string, handler: HandlerContract | string): Route;
|
package/src/Router/Router.js
CHANGED
|
@@ -68,6 +68,9 @@ class Router {
|
|
|
68
68
|
}
|
|
69
69
|
return resourceInstance;
|
|
70
70
|
}
|
|
71
|
+
redirect(url, redirectTo, status = 302) {
|
|
72
|
+
return this.any(url, ({ response }) => response.redirectTo(redirectTo, status));
|
|
73
|
+
}
|
|
71
74
|
get(url, handler) {
|
|
72
75
|
return this.route(url, ['GET', 'HEAD'], handler);
|
|
73
76
|
}
|