c2-http 1.0.133 → 1.0.135
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/dist/middleware/global-middleware/MiddlewareGlobals.js +1 -2
- package/dist/middleware/global-middleware/item/MiddlewareBody.d.ts +0 -1
- package/dist/middleware/global-middleware/item/MiddlewareBody.js +4 -36
- package/dist/middleware/global-middleware/item/MiddlewareContext.js +2 -0
- package/dist/middleware/global-middleware/item/MiddlewareCors.js +21 -17
- package/dist/middleware/global-middleware/item/MiddlewareQueryParams.js +2 -0
- package/package.json +1 -1
|
@@ -5,12 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const MiddlewareBody_1 = __importDefault(require("./item/MiddlewareBody"));
|
|
7
7
|
const MiddlewareContext_1 = __importDefault(require("./item/MiddlewareContext"));
|
|
8
|
-
const MiddlewareCors_1 = __importDefault(require("./item/MiddlewareCors"));
|
|
9
8
|
const MiddlewareLogRequest_1 = __importDefault(require("./item/MiddlewareLogRequest"));
|
|
10
9
|
const MiddlewareQueryParams_1 = __importDefault(require("./item/MiddlewareQueryParams"));
|
|
11
10
|
class MiddlewareGlobals {
|
|
12
11
|
config(expressApplication) {
|
|
13
|
-
|
|
12
|
+
// MiddlewareCors.config(expressApplication);
|
|
14
13
|
MiddlewareContext_1.default.config(expressApplication);
|
|
15
14
|
MiddlewareBody_1.default.config(expressApplication);
|
|
16
15
|
MiddlewareQueryParams_1.default.config(expressApplication);
|
|
@@ -4,52 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const body_parser_1 = __importDefault(require("body-parser"));
|
|
7
|
+
const c2_util_1 = require("c2-util");
|
|
8
|
+
// import moment from "moment";
|
|
7
9
|
class MiddlewareBody {
|
|
8
10
|
config(expressApplication) {
|
|
9
11
|
expressApplication.use(body_parser_1.default.json({ limit: "5mb" }));
|
|
10
12
|
expressApplication.use(body_parser_1.default.urlencoded({ limit: "5mb", extended: true }));
|
|
11
13
|
expressApplication.use(body_parser_1.default.text({ limit: "5mb" }));
|
|
12
14
|
expressApplication.use((request, response, next) => {
|
|
15
|
+
(0, c2_util_1.log)("LOG_BODY", "Body middleware enabled");
|
|
13
16
|
if (request.body && typeof request.body === "object") {
|
|
14
|
-
this.convertDates(request.body, request.headers)
|
|
17
|
+
// this.convertDates(request.body, request.headers)
|
|
15
18
|
}
|
|
16
19
|
next();
|
|
17
20
|
});
|
|
18
21
|
}
|
|
19
|
-
// private convertDates(request: Request): void {
|
|
20
|
-
// for (const key in request.body) {
|
|
21
|
-
// if (request.body.hasOwnProperty(key)) {
|
|
22
|
-
// if (key.endsWith("Date") || key.endsWith("DateTime")) {
|
|
23
|
-
// const tz = request.headers["timezone"] as string || "America/Sao_Paulo" as string; // fallback padrão
|
|
24
|
-
// // interpreta como GMT-3
|
|
25
|
-
// request.body[key] = moment.tz(request.body[key], "YYYY-MM-DD", tz);
|
|
26
|
-
// // obj[key] = moment.utc(obj[key]);
|
|
27
|
-
// } else if (typeof request.body[key] === "object" && request.body[key] !== null) {
|
|
28
|
-
// this.convertDates(request.body[key]);
|
|
29
|
-
// }
|
|
30
|
-
// }
|
|
31
|
-
// }
|
|
32
|
-
// }
|
|
33
|
-
convertDates(obj, headers) {
|
|
34
|
-
// if (Array.isArray(obj)) {
|
|
35
|
-
// // percorre arrays também
|
|
36
|
-
// for (let i = 0; i < obj.length; i++) {
|
|
37
|
-
// this.convertDates(obj[i], headers);
|
|
38
|
-
// }
|
|
39
|
-
// }
|
|
40
|
-
// else if (typeof obj === "object" && obj !== null) {
|
|
41
|
-
// for (const key in obj) {
|
|
42
|
-
// if (!obj.hasOwnProperty(key)) continue;
|
|
43
|
-
// const value = obj[key];
|
|
44
|
-
// if (key.endsWith("Date") || key.endsWith("DateTime")) {
|
|
45
|
-
// const tz = headers["timezone"] || "America/Sao_Paulo"; // fallback padrão
|
|
46
|
-
// obj[key] = moment.tz(value, "YYYY-MM-DD", tz).utc();
|
|
47
|
-
// }
|
|
48
|
-
// else {
|
|
49
|
-
// this.convertDates(value, headers); // recursivo
|
|
50
|
-
// }
|
|
51
|
-
// }
|
|
52
|
-
// }
|
|
53
|
-
}
|
|
54
22
|
}
|
|
55
23
|
exports.default = new MiddlewareBody;
|
|
@@ -3,11 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const c2_util_1 = require("c2-util");
|
|
6
7
|
const express_http_context_1 = __importDefault(require("express-http-context"));
|
|
7
8
|
class MiddlewareContext {
|
|
8
9
|
config(expressApplication) {
|
|
9
10
|
expressApplication.use(express_http_context_1.default.middleware);
|
|
10
11
|
expressApplication.use((request, response, next) => {
|
|
12
|
+
(0, c2_util_1.log)("LOG_CONTEXT", "Context middleware enabled");
|
|
11
13
|
express_http_context_1.default.set("headers", request.headers);
|
|
12
14
|
express_http_context_1.default.set("requestProtocol", request.protocol);
|
|
13
15
|
express_http_context_1.default.set("requestHost", request.hostname);
|
|
@@ -3,27 +3,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const c2_util_1 = require("c2-util");
|
|
6
7
|
const cors_1 = __importDefault(require("cors"));
|
|
7
8
|
class MiddlewareCors {
|
|
8
9
|
config(expressApplication) {
|
|
9
|
-
expressApplication.use((
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
expressApplication.use(() => {
|
|
11
|
+
(0, c2_util_1.log)("LOG_CORS", "CORS middleware enabled");
|
|
12
|
+
return (0, cors_1.default)({
|
|
13
|
+
origin: (origin, callback) => {
|
|
14
|
+
// Permitir solicitações sem uma origem
|
|
15
|
+
if (!origin)
|
|
16
|
+
return callback(null, true);
|
|
17
|
+
if (!process.env.ORIGIN_ENABLES) {
|
|
18
|
+
return callback(null, true);
|
|
19
|
+
}
|
|
20
|
+
if (process.env.ORIGIN_ENABLES.split(",").indexOf(origin) === -1) {
|
|
21
|
+
const msg = "Acesso não permitido para esta origem";
|
|
22
|
+
return callback(new Error(msg), false);
|
|
23
|
+
}
|
|
13
24
|
return callback(null, true);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
return callback(null, true);
|
|
22
|
-
},
|
|
23
|
-
methods: "GET,OPTIONS,PUT,POST,PATCH,DELETE",
|
|
24
|
-
allowedHeaders: "Content-Type,Authorization,Origin,Accept",
|
|
25
|
-
credentials: true
|
|
26
|
-
}));
|
|
25
|
+
},
|
|
26
|
+
methods: "GET,OPTIONS,PUT,POST,PATCH,DELETE",
|
|
27
|
+
allowedHeaders: "Content-Type,Authorization,Origin,Accept",
|
|
28
|
+
credentials: true
|
|
29
|
+
});
|
|
30
|
+
});
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
exports.default = new MiddlewareCors;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MiddlewareQueryParams = void 0;
|
|
4
|
+
const c2_util_1 = require("c2-util");
|
|
4
5
|
class MiddlewareQueryParams {
|
|
5
6
|
config(expressApplication) {
|
|
6
7
|
expressApplication.use((request, response, next) => {
|
|
8
|
+
(0, c2_util_1.log)("LOG_QUERY_PARAMS", "Query params middleware enabled");
|
|
7
9
|
for (const key in request.query) {
|
|
8
10
|
if (request.query.hasOwnProperty(key)) {
|
|
9
11
|
const value = request.query[key];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c2-http",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.135",
|
|
4
4
|
"description": "Biblioteca Typescript para API NodeJS",
|
|
5
5
|
"repository": "https://cabralsilva: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@github.com/cabralsilva/c2-http.git",
|
|
6
6
|
"author": "Daniel Cabral <cabralconsultoriaemsoftware@gmail.com>",
|