From 807073319c5abba2b4b8c053a17ad419cbd5d33b Mon Sep 17 00:00:00 2001 From: Jorge Mendez Ortega Date: Sun, 21 Jun 2020 15:37:34 -0500 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=9B=A0FIX:=20Soporte=20de=20babel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se agrega soporte para las caracteristica de pirvacidad de las clases de JS Issue #3 --- .babelrc.js | 1 + package.json | 1 + 2 files changed, 2 insertions(+) diff --git a/.babelrc.js b/.babelrc.js index 68413d0..354e4de 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -4,6 +4,7 @@ module.exports = { presets: ["@babel/preset-env"], plugins: [ "inline-json-import", + "@babel/plugin-proposal-class-properties", [ "module-resolver", { diff --git a/package.json b/package.json index f267b2c..918d117 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "@babel/cli": "7.10.3", "@babel/core": "7.10.3", "@babel/node": "7.10.3", + "@babel/plugin-proposal-class-properties": "^7.10.1", "@babel/preset-env": "7.10.3", "@babel/register": "7.10.3", "babel-eslint": "10.1.0", From d9bdaee7ae9b5c8e8d9872bcc1345932d096710e Mon Sep 17 00:00:00 2001 From: Jorge Mendez Ortega Date: Sun, 21 Jun 2020 15:38:41 -0500 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9E=95ADD:=20Creaci=C3=B3n=20de=20tools?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se crear las utildades que se utilizaran dentro del aplicativo. Issue #3 --- app/src/tools/Helpers.js | 117 +++++++++++++++++++++++++++++++++++++++ app/src/tools/index.js | 1 + 2 files changed, 118 insertions(+) create mode 100644 app/src/tools/Helpers.js diff --git a/app/src/tools/Helpers.js b/app/src/tools/Helpers.js new file mode 100644 index 0000000..446e4aa --- /dev/null +++ b/app/src/tools/Helpers.js @@ -0,0 +1,117 @@ +import Colors from "cli-color"; + +class Helper { + // Propiedad privada + static #instanceClass = null; + + /** + * Permite limpiar y formatear una cadena + * + * @param {string} string Cadena a limpiar. + * @param {string} union Cararter con el que sera unida. + * + * @retur {string} + */ + formatString(string = "", union = "") { + let ascii = 0; + let char = ""; + let newString = ""; + const STRING = string.toLowerCase(); + const SPECIAL = { + á: "a", + é: "e", + í: "i", + ó: "o", + ú: "u", + ñ: "n", + "♀": "f", + "♂": "m", + }; + + for (let i = 0; i < STRING.length; i += 1) { + char = STRING[i]; + char = (typeof SPECIAL[char] !== "undefined") ? SPECIAL[char] : char; + if (typeof char !== "function") { + ascii = char.charCodeAt(); + newString += (ascii === 32 || (ascii >= 48 && ascii <= 57) || (ascii >= 97 && ascii <= 122)) ? char : ""; + } + } + newString = newString.split(" ").filter(Boolean); + return newString.join(union); + } + + /** + * Permite el seteo de las metas de cache. + * + * @param {express} response Respuesta de express. + * @param {Number} ttl Tiempo de vida de elemento. + * @param {String} type Tipo de elemento. + * + * @return {void} + */ + getTimeToLive(response, ttl = 100, type = "generic") { + const EDGE_VALUE = `API_${type}`.toUpperCase(); + response.setHeader("Edge-Control", `!no-store, cache-maxage=${ttl}s`); + response.setHeader("Edge-Cache-Tag", EDGE_VALUE); + response.setHeader("Cache-Control", `max-age=${ttl}`); + } + + /** + * Permite el envio de mensajes + * + * @param String text Mensaje que se desea mostrar. + * @param String type (Optional) Tipo de mensaje + * + * e = error + * s = succses + * w = warning + * t = tracking + * default = info + * + * @return void. + */ + messages(text, type = "") { + let log = ""; + let msg = ""; + let auxText = typeof text === "object" ? JSON.stringify(text) : text; + const lon = (auxText.length < 90) ? (100 - auxText.length) : 0; + switch (type) { + case "e": + log = Colors.xterm(15).bgXterm(124).bold; + msg = " 🚨 ERROR "; + break; + case "s": + log = Colors.xterm(15).bgXterm(34).bold; + msg = " 🙌 SUCCESS "; + break; + case "w": + log = Colors.xterm(232).bgXterm(214).bold; + msg = " ⚠️ WARNING "; + break; + case "t": + log = Colors.xterm(15).bgXterm(90).bold; + msg = " 🔎 TRACKING "; + break; + default: + log = Colors.xterm(15).bgXterm(12).bold; + msg = " ℹ️ INFO "; + break; + } + for (let i = 0; i < lon; i += 1) { auxText += " "; } + console.log(log(` [${msg}] => ${auxText}`)); + } + + /** + * Permite conseguir una instancia de la clase. + * + * @returns {Helper} + */ + static get instance() { + if (!Helper.#instanceClass) { + Helper.#instanceClass = new Helper(); + } + return Helper.#instanceClass; + } +} + +export default Helper; diff --git a/app/src/tools/index.js b/app/src/tools/index.js index e69de29..bad2b75 100644 --- a/app/src/tools/index.js +++ b/app/src/tools/index.js @@ -0,0 +1 @@ +export { default } from "./Helpers"; \ No newline at end of file From 22e88b123b6888441dc6208d8c0a5dd69abf3d47 Mon Sep 17 00:00:00 2001 From: Jorge Mendez Ortega Date: Sun, 21 Jun 2020 15:39:39 -0500 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9E=95ADD:=20Integraci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se agrega el seguimiento de los eventos del servidor. Issue #3 --- app/src/server/index.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/server/index.js b/app/src/server/index.js index 4157bb6..93b2fab 100644 --- a/app/src/server/index.js +++ b/app/src/server/index.js @@ -6,11 +6,12 @@ import Helmet, { frameguard } from "helmet"; import Path from "path"; import ApiRouter from "./router"; - +import Tools from "Tools/Helpers"; // ======================== CONSTANTES ======================== // const APP_PORT = process.env.PORT; const ROOT_PATH = Path.join(__dirname, "../../"); +const Helpers = Tools.instance; const Server = Express(); // ==================== COMNFIGURACIONES ==================== // @@ -29,7 +30,11 @@ Server.use(BodyParser.json()); // ==================== ARCHIVOS STATICOS ==================== // -Server.use("/", Statics(`${ROOT_PATH}/public/`)); +Server.use("/", Statics(`${ROOT_PATH}/public/`, { + setHeaders(response) { + Helpers.getTimeToLive(response, 31536000, "assets"); + } +})); // ===================== MANEJO DE RUTAS ====================== // @@ -37,10 +42,21 @@ Server.use(ApiRouter(Router)); // ====================== ESTABLECIENDO CONEXIÓN ====================== // +/** + * Inicializacion del servidor. + * + * @param {Number} PORT Puerto por el que estara escuhcando el server. + * @param {Function} Callback Permite identificar el estado del proceso. + * + * return void. + */ Server.listen(APP_PORT, (error) => { + Helpers.messages("Iniciando el Servidor", "i"); if (error) { - console.log(error); + Helpers.messages("Problemas al inicar el servidor", "e"); + console.log(error); // eslint-disable-line + process.exit(1); } else { - console.log(`Servidro listo ${APP_PORT}`); + Helpers.messages(`🚀 Servidor listo en el puerto ${APP_PORT}`, "s"); } });