@athenna/http 3.0.11 → 3.1.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/Commands/MakeControllerCommand.d.ts +15 -0
- package/build/Commands/MakeControllerCommand.js +42 -0
- package/build/Commands/MakeInterceptorCommand.d.ts +15 -0
- package/build/Commands/MakeInterceptorCommand.js +42 -0
- package/build/Commands/MakeMiddlewareCommand.d.ts +15 -0
- package/build/Commands/MakeMiddlewareCommand.js +42 -0
- package/build/Commands/MakeTerminatorCommand.d.ts +15 -0
- package/build/Commands/MakeTerminatorCommand.js +42 -0
- package/build/Commands/RouteListCommand.d.ts +19 -0
- package/build/Commands/RouteListCommand.js +62 -0
- package/build/Context/Request.d.ts +144 -0
- package/build/Context/Request.js +219 -0
- package/build/Context/Response.d.ts +67 -0
- package/build/Context/Response.js +102 -0
- package/build/Contracts/InterceptorContract.d.ts +15 -0
- package/build/Contracts/InterceptorContract.js +9 -0
- package/build/Contracts/MiddlewareContract.d.ts +15 -0
- package/build/Contracts/MiddlewareContract.js +9 -0
- package/build/Contracts/TerminatorContract.d.ts +15 -0
- package/build/Contracts/TerminatorContract.js +9 -0
- package/build/Decorators/Controller.d.ts +14 -0
- package/build/Decorators/Controller.js +28 -0
- package/build/Decorators/Interceptor.d.ts +14 -0
- package/build/Decorators/Interceptor.js +37 -0
- package/build/Decorators/Middleware.d.ts +14 -0
- package/build/Decorators/Middleware.js +37 -0
- package/build/Decorators/Terminator.d.ts +14 -0
- package/build/Decorators/Terminator.js +37 -0
- package/build/Exceptions/BadGatewayException.d.ts +20 -0
- package/build/Exceptions/BadGatewayException.js +22 -0
- package/build/Exceptions/BadRequestException.d.ts +20 -0
- package/build/Exceptions/BadRequestException.js +22 -0
- package/build/Exceptions/ForbiddenException.d.ts +20 -0
- package/build/Exceptions/ForbiddenException.js +22 -0
- package/build/Exceptions/HttpException.d.ts +20 -0
- package/build/Exceptions/HttpException.js +27 -0
- package/build/Exceptions/InternalServerException.d.ts +20 -0
- package/build/Exceptions/InternalServerException.js +22 -0
- package/build/Exceptions/MethodNotAllowedException.d.ts +20 -0
- package/build/Exceptions/MethodNotAllowedException.js +22 -0
- package/build/Exceptions/NotAcceptableException.d.ts +20 -0
- package/build/Exceptions/NotAcceptableException.js +22 -0
- package/build/Exceptions/NotFoundException.d.ts +20 -0
- package/build/Exceptions/NotFoundException.js +22 -0
- package/build/Exceptions/NotImplementedException.d.ts +20 -0
- package/build/Exceptions/NotImplementedException.js +22 -0
- package/build/Exceptions/PayloadTooLargeException.d.ts +20 -0
- package/build/Exceptions/PayloadTooLargeException.js +22 -0
- package/build/Exceptions/RequestTimeoutException.d.ts +20 -0
- package/build/Exceptions/RequestTimeoutException.js +22 -0
- package/build/Exceptions/ServiceUnavailableException.d.ts +20 -0
- package/build/Exceptions/ServiceUnavailableException.js +22 -0
- package/build/Exceptions/UnauthorizedException.d.ts +20 -0
- package/build/Exceptions/UnauthorizedException.js +22 -0
- package/build/Exceptions/UndefinedMethodException.d.ts +12 -0
- package/build/Exceptions/UndefinedMethodException.js +19 -0
- package/build/Exceptions/UnprocessableEntityException.d.ts +20 -0
- package/build/Exceptions/UnprocessableEntityException.js +22 -0
- package/build/Facades/Route.d.ts +10 -0
- package/{src → build}/Facades/Route.js +2 -7
- package/build/Facades/Server.d.ts +10 -0
- package/{src → build}/Facades/Server.js +2 -7
- package/build/Handlers/FastifyHandler.d.ts +41 -0
- package/build/Handlers/FastifyHandler.js +116 -0
- package/build/Handlers/HttpExceptionHandler.d.ts +31 -0
- package/build/Handlers/HttpExceptionHandler.js +82 -0
- package/build/Kernels/HttpKernel.d.ts +73 -0
- package/build/Kernels/HttpKernel.js +221 -0
- package/build/Providers/HttpRouteProvider.d.ts +12 -0
- package/build/Providers/HttpRouteProvider.js +15 -0
- package/build/Providers/HttpServerProvider.d.ts +13 -0
- package/build/Providers/HttpServerProvider.js +25 -0
- package/build/Router/Route.d.ts +263 -0
- package/build/Router/Route.js +447 -0
- package/build/Router/RouteGroup.d.ts +96 -0
- package/build/Router/RouteGroup.js +123 -0
- package/build/Router/RouteResource.d.ts +108 -0
- package/build/Router/RouteResource.js +158 -0
- package/build/Router/Router.d.ts +103 -0
- package/build/Router/Router.js +188 -0
- package/build/Server/ServerImpl.d.ts +129 -0
- package/build/Server/ServerImpl.js +213 -0
- package/build/Types/Contexts/Context.d.ts +20 -0
- package/build/Types/Contexts/Context.js +9 -0
- package/build/Types/Contexts/ErrorContext.d.ts +21 -0
- package/build/Types/Contexts/ErrorContext.js +9 -0
- package/build/Types/Contexts/InterceptContext.d.ts +20 -0
- package/build/Types/Contexts/InterceptContext.js +9 -0
- package/build/Types/Contexts/TerminateContext.d.ts +21 -0
- package/build/Types/Contexts/TerminateContext.js +9 -0
- package/build/Types/Controllers/ControllerOptions.d.ts +25 -0
- package/build/Types/Controllers/ControllerOptions.js +9 -0
- package/build/Types/Middlewares/InterceptorRouteType.d.ts +11 -0
- package/build/Types/Middlewares/InterceptorRouteType.js +9 -0
- package/build/Types/Middlewares/MiddlewareHandler.d.ts +20 -0
- package/build/Types/Middlewares/MiddlewareHandler.js +9 -0
- package/build/Types/Middlewares/MiddlewareOptions.d.ts +40 -0
- package/build/Types/Middlewares/MiddlewareOptions.js +9 -0
- package/build/Types/Middlewares/MiddlewareRouteType.d.ts +11 -0
- package/build/Types/Middlewares/MiddlewareRouteType.js +9 -0
- package/build/Types/Middlewares/TerminatorRouteType.d.ts +11 -0
- package/build/Types/Middlewares/TerminatorRouteType.js +9 -0
- package/build/Types/Router/RouteHandler.d.ts +10 -0
- package/build/Types/Router/RouteHandler.js +9 -0
- package/build/Types/Router/RouteJSON.d.ts +21 -0
- package/build/Types/Router/RouteJSON.js +9 -0
- package/build/Types/Router/RouteResourceTypes.d.ts +9 -0
- package/build/Types/Router/RouteResourceTypes.js +9 -0
- package/build/index.d.ts +70 -0
- package/build/index.js +48 -0
- package/package.json +159 -77
- package/templates/controller.edge +8 -36
- package/templates/interceptor.edge +8 -0
- package/templates/middleware.edge +4 -36
- package/templates/terminator.edge +6 -0
- package/src/Commands/Make/Controller.js +0 -64
- package/src/Commands/Make/Middleware.js +0 -80
- package/src/Commands/Route/List.js +0 -107
- package/src/Context/Request.js +0 -268
- package/src/Context/Response.js +0 -173
- package/src/Exceptions/BadGatewayException.js +0 -31
- package/src/Exceptions/BadRequestException.js +0 -31
- package/src/Exceptions/ForbiddenException.js +0 -31
- package/src/Exceptions/HttpException.js +0 -33
- package/src/Exceptions/InternalServerException.js +0 -31
- package/src/Exceptions/MethodNotAllowedException.js +0 -31
- package/src/Exceptions/NotAcceptableException.js +0 -31
- package/src/Exceptions/NotFoundException.js +0 -31
- package/src/Exceptions/NotImplementedException.js +0 -31
- package/src/Exceptions/PayloadTooLargeException.js +0 -31
- package/src/Exceptions/RequestTimeoutException.js +0 -31
- package/src/Exceptions/ServiceUnavailableException.js +0 -31
- package/src/Exceptions/UnauthorizedException.js +0 -31
- package/src/Exceptions/UndefinedMethodException.js +0 -30
- package/src/Exceptions/UnprocessableEntityException.js +0 -31
- package/src/Handlers/FastifyHandler.js +0 -148
- package/src/Handlers/HttpExceptionHandler.js +0 -88
- package/src/Helpers/HttpLoader.js +0 -38
- package/src/Kernels/HttpKernel.js +0 -199
- package/src/Providers/ControllerProvider.js +0 -29
- package/src/Providers/HttpRouteProvider.js +0 -24
- package/src/Providers/HttpServerProvider.js +0 -37
- package/src/Providers/MiddlewareProvider.js +0 -29
- package/src/Router/Route.js +0 -411
- package/src/Router/RouteGroup.js +0 -119
- package/src/Router/RouteResource.js +0 -247
- package/src/Router/Router.js +0 -313
- package/src/Utils/isMiddlewareContract.js +0 -17
- package/src/Utils/removeSlashes.js +0 -30
- package/src/index.d.ts +0 -1395
- package/src/index.js +0 -377
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @athenna/http
|
|
3
|
-
*
|
|
4
|
-
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import rTracer from 'cls-rtracer'
|
|
11
|
-
|
|
12
|
-
import { Log, Logger } from '@athenna/logger'
|
|
13
|
-
import { Config } from '@athenna/config'
|
|
14
|
-
import { Server } from '#src/Facades/Server'
|
|
15
|
-
import { Module, Path } from '@athenna/common'
|
|
16
|
-
|
|
17
|
-
export class HttpKernel {
|
|
18
|
-
/**
|
|
19
|
-
* The application's global HTTP middlewares.
|
|
20
|
-
*
|
|
21
|
-
* This middlewares are run during every request to your http server.
|
|
22
|
-
*
|
|
23
|
-
* @return {any[] | Promise<any[]>}
|
|
24
|
-
*/
|
|
25
|
-
get globalMiddlewares() {
|
|
26
|
-
return []
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The application's named HTTP middlewares.
|
|
31
|
-
*
|
|
32
|
-
* Here you define all your named middlewares to use inside routes/http file.
|
|
33
|
-
*
|
|
34
|
-
* @return {Record<string, any | Promise<any>>}
|
|
35
|
-
*/
|
|
36
|
-
get namedMiddlewares() {
|
|
37
|
-
return {}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Register all global and named middlewares to the server.
|
|
42
|
-
*
|
|
43
|
-
* @return void
|
|
44
|
-
*/
|
|
45
|
-
async registerMiddlewares() {
|
|
46
|
-
const subAlias = 'App/Http/Middlewares'
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Binding the named middlewares inside the container and
|
|
50
|
-
* creating a simple alias to use it inside Route.
|
|
51
|
-
*/
|
|
52
|
-
for (const key of Object.keys(this.namedMiddlewares)) {
|
|
53
|
-
const midModule = this.namedMiddlewares[key]
|
|
54
|
-
|
|
55
|
-
const { alias, module } = await Module.getWithAlias(midModule, subAlias)
|
|
56
|
-
|
|
57
|
-
if (!ioc.hasDependency(alias)) {
|
|
58
|
-
ioc.bind(alias, module)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
ioc.alias(`App/Http/Middlewares/Names/${key}`, alias)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Binding the global middlewares inside the container and
|
|
66
|
-
* resolving it inside the Http server using "use" method.
|
|
67
|
-
*/
|
|
68
|
-
for (const midModule of this.globalMiddlewares) {
|
|
69
|
-
const { alias, module } = await Module.getWithAlias(midModule, subAlias)
|
|
70
|
-
|
|
71
|
-
if (!ioc.hasDependency(alias)) {
|
|
72
|
-
ioc.bind(alias, module)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const Middleware = ioc.safeUse(alias)
|
|
76
|
-
|
|
77
|
-
if (Middleware.handle) {
|
|
78
|
-
Server.use(Middleware.handle, 'handle')
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (Middleware.intercept) {
|
|
82
|
-
Server.use(Middleware.intercept, 'intercept')
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (Middleware.terminate) {
|
|
86
|
-
Server.use(Middleware.terminate, 'terminate')
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Register cors plugin.
|
|
93
|
-
*
|
|
94
|
-
* @return {Promise<void>}
|
|
95
|
-
*/
|
|
96
|
-
async registerCors() {
|
|
97
|
-
if (Config.is('http.noCors', true)) {
|
|
98
|
-
return
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
await Server.registerCors(Config.get('http.cors'))
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Register the rTracer plugin.
|
|
106
|
-
*
|
|
107
|
-
* @return {Promise<void>}
|
|
108
|
-
*/
|
|
109
|
-
async registerTracer() {
|
|
110
|
-
if (Config.is('http.noTracer', true)) {
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
Server.use(async ctx => (ctx.data.traceId = rTracer.id()))
|
|
115
|
-
|
|
116
|
-
await Server.registerTracer(Config.get('http.tracer'))
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Register helmet plugin.
|
|
121
|
-
*
|
|
122
|
-
* @return {Promise<void>}
|
|
123
|
-
*/
|
|
124
|
-
async registerHelmet() {
|
|
125
|
-
if (Config.is('http.noHelmet', true)) {
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
await Server.registerHelmet(Config.get('http.helmet'))
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Register swagger plugin.
|
|
134
|
-
*
|
|
135
|
-
* @return {Promise<void>}
|
|
136
|
-
*/
|
|
137
|
-
async registerSwagger() {
|
|
138
|
-
if (Config.is('http.noSwagger', true)) {
|
|
139
|
-
return
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
await Server.registerSwagger(Config.get('http.swagger'))
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Register rate limit plugin.
|
|
147
|
-
*
|
|
148
|
-
* @return {Promise<void>}
|
|
149
|
-
*/
|
|
150
|
-
async registerRateLimit() {
|
|
151
|
-
if (Config.is('http.noRateLimit', true)) {
|
|
152
|
-
return
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
await Server.registerRateLimit(Config.get('http.rateLimit'))
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Register the default error handler.
|
|
160
|
-
*
|
|
161
|
-
* @return {Promise<void>}
|
|
162
|
-
*/
|
|
163
|
-
async registerErrorHandler() {
|
|
164
|
-
if (Config.is('http.noErrorHandler', true)) {
|
|
165
|
-
return
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const Handler = await Module.getFrom(
|
|
169
|
-
Path.http(`Exceptions/Handler.${Path.ext()}`),
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
const handler = new Handler()
|
|
173
|
-
|
|
174
|
-
Server.setErrorHandler(handler.handle.bind(handler))
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Register log terminate middleware.
|
|
179
|
-
*
|
|
180
|
-
* @return {Promise<void>}
|
|
181
|
-
*/
|
|
182
|
-
async registerLogMiddleware() {
|
|
183
|
-
if (Config.is('http.logRequests', false)) {
|
|
184
|
-
return
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
Server.use(async ctx => {
|
|
188
|
-
const logger = Config.exists('logging.channels.request')
|
|
189
|
-
? Log.channel('request')
|
|
190
|
-
: Logger.getVanillaLogger({
|
|
191
|
-
level: 'trace',
|
|
192
|
-
driver: 'console',
|
|
193
|
-
formatter: 'none',
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
logger.info(ctx)
|
|
197
|
-
}, 'terminate')
|
|
198
|
-
}
|
|
199
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @athenna/http
|
|
3
|
-
*
|
|
4
|
-
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { Module, Path } from '@athenna/common'
|
|
11
|
-
import { ServiceProvider } from '@athenna/ioc'
|
|
12
|
-
|
|
13
|
-
export class ControllerProvider extends ServiceProvider {
|
|
14
|
-
/**
|
|
15
|
-
* Bootstrap any application services.
|
|
16
|
-
*
|
|
17
|
-
* @return {Promise<void>}
|
|
18
|
-
*/
|
|
19
|
-
async boot() {
|
|
20
|
-
const path = Path.http('Controllers')
|
|
21
|
-
const subAlias = 'App/Http/Controllers'
|
|
22
|
-
|
|
23
|
-
const controllers = await Module.getAllFromWithAlias(path, subAlias)
|
|
24
|
-
|
|
25
|
-
controllers.forEach(({ alias, module }) => {
|
|
26
|
-
this.container.bind(alias, module)
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @athenna/http
|
|
3
|
-
*
|
|
4
|
-
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { Router } from '#src/Router/Router'
|
|
11
|
-
import { ServiceProvider } from '@athenna/ioc'
|
|
12
|
-
|
|
13
|
-
export class HttpRouteProvider extends ServiceProvider {
|
|
14
|
-
/**
|
|
15
|
-
* Bootstrap any application services.
|
|
16
|
-
*
|
|
17
|
-
* @return {void}
|
|
18
|
-
*/
|
|
19
|
-
boot() {
|
|
20
|
-
const http = this.container.safeUse('Athenna/Core/HttpServer')
|
|
21
|
-
|
|
22
|
-
this.container.instance('Athenna/Core/HttpRoute', new Router(http))
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @athenna/http
|
|
3
|
-
*
|
|
4
|
-
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { Http } from '#src/index'
|
|
11
|
-
import { ServiceProvider } from '@athenna/ioc'
|
|
12
|
-
|
|
13
|
-
export class HttpServerProvider extends ServiceProvider {
|
|
14
|
-
/**
|
|
15
|
-
* Register any application services.
|
|
16
|
-
*
|
|
17
|
-
* @return {void}
|
|
18
|
-
*/
|
|
19
|
-
register() {
|
|
20
|
-
this.container.instance('Athenna/Core/HttpServer', new Http())
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Shutdown any application services.
|
|
25
|
-
*
|
|
26
|
-
* @return {void|Promise<void>}
|
|
27
|
-
*/
|
|
28
|
-
async shutdown() {
|
|
29
|
-
const Server = this.container.use('Athenna/Core/HttpServer')
|
|
30
|
-
|
|
31
|
-
if (!Server) {
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
await Server.close()
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @athenna/http
|
|
3
|
-
*
|
|
4
|
-
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { Module, Path } from '@athenna/common'
|
|
11
|
-
import { ServiceProvider } from '@athenna/ioc'
|
|
12
|
-
|
|
13
|
-
export class MiddlewareProvider extends ServiceProvider {
|
|
14
|
-
/**
|
|
15
|
-
* Bootstrap any application services.
|
|
16
|
-
*
|
|
17
|
-
* @return {Promise<void>}
|
|
18
|
-
*/
|
|
19
|
-
async boot() {
|
|
20
|
-
const path = Path.http('Middlewares')
|
|
21
|
-
const subAlias = 'App/Http/Middlewares'
|
|
22
|
-
|
|
23
|
-
const middlewares = await Module.getAllFromWithAlias(path, subAlias)
|
|
24
|
-
|
|
25
|
-
middlewares.forEach(({ alias, module }) => {
|
|
26
|
-
this.container.singleton(alias, module)
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
}
|