@athenna/http 1.2.0 → 1.2.3
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/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +2 -2
- package/src/Facades/Route.d.ts +10 -0
- package/src/Facades/Route.js +13 -0
- package/src/Facades/Server.d.ts +10 -0
- package/src/Facades/Server.js +13 -0
- package/src/Handlers/HttpErrorHandler.js +12 -14
- package/src/Utils/Handler.d.ts +13 -0
- package/src/Utils/Handler.js +24 -0
package/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
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
|
+
export * from './src/Facades/Route';
|
|
10
|
+
export * from './src/Facades/Server';
|
|
9
11
|
export * from './src/Http';
|
|
10
12
|
export * from './src/Router/Router';
|
|
11
13
|
export * from './src/Kernels/HttpKernel';
|
package/index.js
CHANGED
|
@@ -18,6 +18,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
18
18
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
__exportStar(require("./src/Facades/Route"), exports);
|
|
22
|
+
__exportStar(require("./src/Facades/Server"), exports);
|
|
21
23
|
__exportStar(require("./src/Http"), exports);
|
|
22
24
|
__exportStar(require("./src/Router/Router"), exports);
|
|
23
25
|
__exportStar(require("./src/Kernels/HttpKernel"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/http",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
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>",
|
|
@@ -160,7 +160,7 @@
|
|
|
160
160
|
"dependencies": {
|
|
161
161
|
"@athenna/config": "1.0.8",
|
|
162
162
|
"@athenna/ioc": "1.1.2",
|
|
163
|
-
"@athenna/logger": "1.1.
|
|
163
|
+
"@athenna/logger": "1.1.6",
|
|
164
164
|
"@secjs/utils": "1.8.3",
|
|
165
165
|
"fastify": "3.27.4",
|
|
166
166
|
"reflect-metadata": "0.1.13",
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
import { Router } from '../Router/Router';
|
|
10
|
+
export declare const Route: Router;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @athenna/http
|
|
4
|
+
*
|
|
5
|
+
* (c) João Lenon <lenon@athenna.io>
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.Route = void 0;
|
|
12
|
+
const Handler_1 = require("../Utils/Handler");
|
|
13
|
+
exports.Route = new Proxy({}, new Handler_1.Handler('Athenna/Core/HttpRoute'));
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
import { Http } from '../Http';
|
|
10
|
+
export declare const Server: Http;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @athenna/http
|
|
4
|
+
*
|
|
5
|
+
* (c) João Lenon <lenon@athenna.io>
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.Server = void 0;
|
|
12
|
+
const Handler_1 = require("../Utils/Handler");
|
|
13
|
+
exports.Server = new Proxy({}, new Handler_1.Handler('Athenna/Core/HttpServer'));
|
|
@@ -17,26 +17,24 @@ class HttpErrorHandler {
|
|
|
17
17
|
const code = error.code || error.name;
|
|
18
18
|
const statusCode = error.statusCode || error.status || 500;
|
|
19
19
|
const body = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
stack: error.stack,
|
|
26
|
-
},
|
|
20
|
+
statusCode,
|
|
21
|
+
code: utils_1.String.toSnakeCase(`${code}`).toUpperCase(),
|
|
22
|
+
name: error.name,
|
|
23
|
+
message: error.message,
|
|
24
|
+
stack: error.stack,
|
|
27
25
|
};
|
|
28
26
|
if (error.help) {
|
|
29
|
-
body.
|
|
27
|
+
body.help = error.help;
|
|
30
28
|
}
|
|
31
29
|
const isInternalServerError = statusCode === 500;
|
|
32
|
-
const isDebugMode =
|
|
30
|
+
const isDebugMode = config_1.Config.get('app.debug');
|
|
33
31
|
if (isInternalServerError && !isDebugMode) {
|
|
34
|
-
body.
|
|
35
|
-
body.
|
|
36
|
-
delete body.
|
|
32
|
+
body.name = 'Internal server error';
|
|
33
|
+
body.message = 'An internal server exception has occurred.';
|
|
34
|
+
delete body.stack;
|
|
37
35
|
}
|
|
38
|
-
if (
|
|
39
|
-
new logger_1.Logger().error(`Error: ${JSON.stringify(body
|
|
36
|
+
if (isDebugMode) {
|
|
37
|
+
new logger_1.Logger().error(`Error: ${JSON.stringify(body, null, 2)}`, {
|
|
40
38
|
formatterConfig: {
|
|
41
39
|
context: HttpErrorHandler.name,
|
|
42
40
|
},
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
export declare class Handler {
|
|
10
|
+
private readonly alias;
|
|
11
|
+
constructor(alias: any);
|
|
12
|
+
get(_object: any, key: string): any;
|
|
13
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @athenna/http
|
|
4
|
+
*
|
|
5
|
+
* (c) João Lenon <lenon@athenna.io>
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.Handler = void 0;
|
|
12
|
+
class Handler {
|
|
13
|
+
constructor(alias) {
|
|
14
|
+
this.alias = alias;
|
|
15
|
+
}
|
|
16
|
+
get(_object, key) {
|
|
17
|
+
const provider = ioc.use(this.alias);
|
|
18
|
+
if (!provider) {
|
|
19
|
+
return () => { };
|
|
20
|
+
}
|
|
21
|
+
return provider[key];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.Handler = Handler;
|