diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..6c4c868 Binary files /dev/null and b/.DS_Store differ diff --git a/.env b/.env index a4b041c..8e63afd 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -PORT=1800 +PORT=1900 DDOSSTATUS=0 -DDOSINTENTOS=3 -DDOSTIMOUT=600000 \ No newline at end of file +DDOSINTENTOS=10 +DDOSTIMOUT=10000 # 86400000 es un dia \ No newline at end of file diff --git a/db/.DS_Store b/db/.DS_Store new file mode 100644 index 0000000..6471031 Binary files /dev/null and b/db/.DS_Store differ diff --git a/db/datastores.json b/db/datastores.json index 8ffaa34..e008f7c 100644 --- a/db/datastores.json +++ b/db/datastores.json @@ -1,14 +1,17 @@ { "datastore":[ { - "name": "manager", + "name": "test", "conn":{ "server": "localhost", "user": "root", "password": "", "port": 3306, "connectionreintent": 5, - "database": "" + "database": "test", + "connectionLimit": 10, + "waitForConnections": 10, + "queueLimit": 10 } } ] diff --git a/db/endpoint_stats.db b/db/endpoint_stats.db new file mode 100644 index 0000000..700fee4 Binary files /dev/null and b/db/endpoint_stats.db differ diff --git a/index.js b/index.js index ddb6965..3a4d19e 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ require("dotenv").config(); global.datetoDay = require("./modules/date").datetoDay global.dateNow = require("./modules/date").dateNow +global.dateDB = require("./modules/date").dateDB global.datetoJSON = require("./modules/date").datetoJSON global.log = require("./modules/log4j").log global.port = parseInt(process.env.PORT) || 3000; diff --git a/modules/date.js b/modules/date.js index c944139..0b04ee2 100644 --- a/modules/date.js +++ b/modules/date.js @@ -4,6 +4,11 @@ const formatearFecha = (fecha) => { return fecha.setZone('America/Argentina/Buenos_Aires'); }; +const dateDB = () => { + let date = formatearFecha(DateTime.local()); + return date.toFormat('yyyy-MM-dd HH:mm:ss'); +}; + const dateNow = () => { let date = formatearFecha(DateTime.local()); return date.toLocaleString(DateTime.DATETIME_FULL); @@ -29,5 +34,6 @@ const datetoJSON = () => { module.exports = { datetoDay, dateNow, - datetoJSON + datetoJSON, + dateDB }; \ No newline at end of file diff --git a/modules/expressHandle.js b/modules/expressHandle.js index 02f5ad1..9749eff 100644 --- a/modules/expressHandle.js +++ b/modules/expressHandle.js @@ -5,7 +5,7 @@ const blockedIPs = []; exports.reqInfo = (req) =>{ return { id: randomUUID(), - ip: req.headers['x-forwarded-for'] || req.socket.remoteAddress, + ip: req.headers['x-forwarded-for'], uri: req.originalUrl, method: req.method } @@ -82,9 +82,6 @@ exports.DDOSBlock = (req, res, next) => { next(); } - - - setInterval(() => { const currentTime = new Date(); blockedIPs.forEach((ip, index) => { diff --git a/modules/sql.js b/modules/sql.js index c5705fe..526e6ab 100644 --- a/modules/sql.js +++ b/modules/sql.js @@ -1,78 +1,93 @@ -const mysql = require("mysql2"); -const mysqlSy = require('sync-mysql') const dbconect = require("../db/datastores.json").datastore +const mysql = require('mysql2/promise'); -function executeSQL(database, sql) { - let dataconnection; - const selectedDB = dbconect.find(item => item.name === database); +async function executeSQLS(database, sql) { + try { + const selectedDB = dbconect.find(item => item.name === database); + + if (!selectedDB) { + log("error", `El Conector "${database}" no es correcto o no existe`, "SQL"); + return { status: 0 }; + } - if (selectedDB) { - dataconnection = mysql.createConnection({ + const pool = mysql.createPool({ + connectionLimit: selectedDB.conn.connectionLimit, host: selectedDB.conn.server, user: selectedDB.conn.user, password: selectedDB.conn.password, - connectTimeout: selectedDB.conn.connectTimeout, database: selectedDB.conn.database, - multipleStatements: true + waitForConnections: true, + queueLimit: 0 }); - } else { - log("error", `El Conector "${database}" no es correcto o no existe`, "SQL"); - return Promise.resolve({ status: 0 }); - } - - return new Promise((resolve, reject) => { - try { - dataconnection.query(sql, (error, results) => { - if (error) { - log("error", `Existe un error en la consulta :: ${error}`, "SQL"); - resolve({ status: 0 }); - } - resolve(results); - }); - } catch (error) { - log("error", `Existe un error en la consulta :: ${error}`, "SQL"); - resolve({ status: 0 }); - } - }); -} - -function executeSQLS (database, sql) { - try{ - let connection; - let response; - - const selectedDB = dbconect.find(item => item.name === database); + const [rows, fields] = await pool.execute(sql); - if (selectedDB) { + await pool.end(); - connection = new mysqlSy({ - host: selectedDB.conn.server, - user: selectedDB.conn.user, - password: selectedDB.conn.password, - connectTimeout: selectedDB.conn.connectTimeout, - database: selectedDB.conn.database - }); + return rows; + } catch (error) { + log("error", `Existe un error en la consulta :: ${error}`, "SQL"); + if (error.code === 'PROTOCOL_CONNECTION_LOST') { + // Si la conexión se pierde, se vuelve a intentar una vez + log("warning", `Se perdió la conexión con la base de datos. Reintentando la consulta...`, "SQL"); + return executeSQLS(database, sql); + } else if (error.code === 'POOL_ENQUEUELIMIT') { + // Si se alcanza el límite de la pool, se muestra una advertencia y se espera antes de reintentar + log("warning", `Se alcanzó el límite de conexiones permitido. Esperando antes de reintentar...`, "SQL"); + await new Promise(resolve => setTimeout(resolve, 5000)); + return executeSQLS(database, sql); } else { + // Cualquier otro error se maneja como una falla + return { status: 0 }; + } + } +} + +async function executeSQL(database, sql, values) { + try { + const selectedDB = dbconect.find(item => item.name === database); + if (!selectedDB) { log("error", `El Conector "${database}" no es correcto o no existe`, "SQL"); return { status: 0 }; - } - response = connection.query(sql) - connection.finishAll() + const pool = mysql.createPool({ + connectionLimit: selectedDB.conn.connectionLimit, + host: selectedDB.conn.server, + user: selectedDB.conn.user, + password: selectedDB.conn.password, + database: selectedDB.conn.database, + waitForConnections: true, + queueLimit: 0 + }); + + const [rows, fields] = await pool.execute(sql, values); - return response; + await pool.end(); + return rows; } catch (error) { - log("error", `Existe un error en la consulta :: ${error}`, "SQL") - return { status: 0 }; + log("error", `Existe un error en la consulta :: ${error}`, "SQL"); + + if (error.code === 'PROTOCOL_CONNECTION_LOST') { + // Si la conexión se pierde, se vuelve a intentar una vez + log("warning", `Se perdió la conexión con la base de datos. Reintentando la consulta...`, "SQL"); + return executeSQLS(database, sql, values); + } else if (error.code === 'POOL_ENQUEUELIMIT') { + // Si se alcanza el límite de la pool, se muestra una advertencia y se espera antes de reintentar + log("warning", `Se alcanzó el límite de conexiones permitido. Esperando antes de reintentar...`, "SQL"); + await new Promise(resolve => setTimeout(resolve, 5000)); + return executeSQLS(database, sql, values); + } else { + // Cualquier otro error se maneja como una falla + return { status: 0 }; + } } } -module.exports = { - executeSQL, - executeSQLS -}; \ No newline at end of file + +exports.executeSQLS = executeSQLS; + +exports.executeSQL = executeSQL diff --git a/package-lock.json b/package-lock.json index 985b3f6..66edca7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "monointegrator", - "version": "2.0.0", + "version": "2.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "monointegrator", - "version": "2.0.0", + "version": "2.0.1", "license": "Apache-2.0", "dependencies": { "cors": "^2.8.5", @@ -16,9 +16,9 @@ "log4js": "^6.6.1", "luxon": "^3.0.1", "mysql": "^2.18.1", - "mysql2": "^3.1.1", + "mysql2": "^3.2.0", "sqlite3": "^5.1.4", - "sync-mysql": "^3.0.1" + "uuid": "^9.0.0" }, "devDependencies": { "nodemon": "^2.0.19" @@ -312,46 +312,11 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" }, - "node_modules/asap": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", - "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==" - }, - "node_modules/babel-runtime": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", - "integrity": "sha512-ITKNuq2wKlW1fJg9sSW52eepoYgZBggvOAHC0u/CYu/qxQ9EVzThCgR69BnSXLHjy2f7SY5zaQ4yt7H9ZVxY2g==", - "dependencies": { - "core-js": "^2.4.0", - "regenerator-runtime": "^0.11.0" - } - }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, - "node_modules/barrage": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/barrage/-/barrage-1.1.0.tgz", - "integrity": "sha512-lmhNsUZG+34gUrZl0SKOeYZ20o4Xni2wd52fzzrIsniQqoqfwa3otEP4Vceks+KwGACNsnQ1YSYtsaPWHrQ+3Q==", - "dependencies": { - "promise": "^6.0.0" - } - }, - "node_modules/barrage/node_modules/asap": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/asap/-/asap-1.0.0.tgz", - "integrity": "sha512-Ej9qjcXY+8Tuy1cNqiwNMwFRXOy9UwgTeMA8LxreodygIPV48lx8PU1ecFxb5ZeU1DpMKxiq6vGLTxcitWZPbA==" - }, - "node_modules/barrage/node_modules/promise": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/promise/-/promise-6.1.0.tgz", - "integrity": "sha512-O+uwGKreKNKkshzZv2P7N64lk6EP17iXBn0PbUnNQhk+Q0AHLstiTrjkx3v5YBd3cxUe7Sq6KyRhl/A0xUjk7Q==", - "dependencies": { - "asap": "~1.0.0" - } - }, "node_modules/bignumber.js": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", @@ -437,11 +402,6 @@ "node": ">=8" } }, - "node_modules/buffer-from": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" - }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -560,20 +520,6 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, - "node_modules/concat-stream": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", - "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", - "engines": [ - "node >= 0.8" - ], - "dependencies": { - "buffer-from": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^2.2.2", - "typedarray": "^0.0.6" - } - }, "node_modules/console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", @@ -611,13 +557,6 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==" }, - "node_modules/core-js": { - "version": "2.6.12", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.12.tgz", - "integrity": "sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==", - "deprecated": "core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.", - "hasInstallScript": true - }, "node_modules/core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", @@ -958,14 +897,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/get-port": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/get-port/-/get-port-3.2.0.tgz", - "integrity": "sha512-x5UJKlgeUiNT8nyo/AcnwLnZuZNcSjSw0kogRB+Whd1fjjFq4B1hySFxSFWWSn4mIBzg3sRNUDFYc4g5gjPoLg==", - "engines": { - "node": ">=4" - } - }, "node_modules/glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", @@ -1599,15 +1530,15 @@ "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, "node_modules/mysql2": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.1.1.tgz", - "integrity": "sha512-mXz4wEj7AIKPdHQJLJcvq8GJ75BDMH9K4V8Lthra8WH7o/xjV6TXp+dXAXDaMFkLa8YhdZr5X6rxIGQSHPPfhg==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.4.1.tgz", + "integrity": "sha512-1VBrTIjDacTgcQ3/jUnMlix7twU3VfQtlAcBFPn5524AnBZcENRnpmdFt6oZaiYu4yGkAWXu0InNMg/LQs4daQ==", "dependencies": { "denque": "^2.1.0", "generate-function": "^2.3.1", "iconv-lite": "^0.6.3", "long": "^5.2.1", - "lru-cache": "^7.14.1", + "lru-cache": "^8.0.0", "named-placeholders": "^1.1.3", "seq-queue": "^0.0.5", "sqlstring": "^2.3.2" @@ -1616,6 +1547,14 @@ "node": ">= 8.0" } }, + "node_modules/mysql2/node_modules/lru-cache": { + "version": "8.0.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-8.0.5.tgz", + "integrity": "sha512-MhWWlVnuab1RG5/zMRRcVGXZLCXrZTgfwMikgzCegsPnG62yDQo5JnqKkrK4jO5iKqDAZGItAqN5CtKBCBWRUA==", + "engines": { + "node": ">=16.14" + } + }, "node_modules/mysql2/node_modules/sqlstring": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz", @@ -1946,14 +1885,6 @@ "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, - "node_modules/promise": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz", - "integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==", - "dependencies": { - "asap": "~2.0.3" - } - }, "node_modules/promise-inflight": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz", @@ -2069,11 +2000,6 @@ "node": ">=8.10.0" } }, - "node_modules/regenerator-runtime": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", - "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" - }, "node_modules/retry": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz", @@ -2433,25 +2359,6 @@ "node": ">=4" } }, - "node_modules/sync-mysql": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/sync-mysql/-/sync-mysql-3.0.1.tgz", - "integrity": "sha512-EKWJFuiPRtj1s6bjSaf4tzMFeq8x0JgKtgyIsTTkD20E8pkzInEFxj1B+efbYMjQUfN9MEY3HOsaSYUmSbsUKw==", - "dependencies": { - "babel-runtime": "^6.18.0", - "concat-stream": "^1.6.0", - "sync-rpc": "^1.1.1", - "then-mysql": "^1.1.1" - } - }, - "node_modules/sync-rpc": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/sync-rpc/-/sync-rpc-1.3.6.tgz", - "integrity": "sha512-J8jTXuZzRlvU7HemDgHi3pGnh/rkoqR/OZSjhTyyZrEkkYQbk7Z33AXp37mkPfPpfdOuj7Ex3H/TJM1z48uPQw==", - "dependencies": { - "get-port": "^3.1.0" - } - }, "node_modules/tar": { "version": "6.1.13", "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.13.tgz", @@ -2476,16 +2383,6 @@ "node": ">=8" } }, - "node_modules/then-mysql": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/then-mysql/-/then-mysql-1.1.1.tgz", - "integrity": "sha512-QqWODY1xtWFo3XR4GllWFkXMTz+QirJKcggMETNPeGqPDcxUyApqDW5GgAUJEz4Dga3/WrXNmZY0bT+cAWjQ2g==", - "dependencies": { - "barrage": "^1.1.0", - "mysql": "^2.10.0", - "promise": "^7.1.1" - } - }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -2535,11 +2432,6 @@ "node": ">= 0.6" } }, - "node_modules/typedarray": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==" - }, "node_modules/undefsafe": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", @@ -2593,6 +2485,14 @@ "node": ">= 0.4.0" } }, + "node_modules/uuid": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", + "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -2871,48 +2771,11 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" }, - "asap": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", - "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==" - }, - "babel-runtime": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", - "integrity": "sha512-ITKNuq2wKlW1fJg9sSW52eepoYgZBggvOAHC0u/CYu/qxQ9EVzThCgR69BnSXLHjy2f7SY5zaQ4yt7H9ZVxY2g==", - "requires": { - "core-js": "^2.4.0", - "regenerator-runtime": "^0.11.0" - } - }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, - "barrage": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/barrage/-/barrage-1.1.0.tgz", - "integrity": "sha512-lmhNsUZG+34gUrZl0SKOeYZ20o4Xni2wd52fzzrIsniQqoqfwa3otEP4Vceks+KwGACNsnQ1YSYtsaPWHrQ+3Q==", - "requires": { - "promise": "^6.0.0" - }, - "dependencies": { - "asap": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/asap/-/asap-1.0.0.tgz", - "integrity": "sha512-Ej9qjcXY+8Tuy1cNqiwNMwFRXOy9UwgTeMA8LxreodygIPV48lx8PU1ecFxb5ZeU1DpMKxiq6vGLTxcitWZPbA==" - }, - "promise": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/promise/-/promise-6.1.0.tgz", - "integrity": "sha512-O+uwGKreKNKkshzZv2P7N64lk6EP17iXBn0PbUnNQhk+Q0AHLstiTrjkx3v5YBd3cxUe7Sq6KyRhl/A0xUjk7Q==", - "requires": { - "asap": "~1.0.0" - } - } - } - }, "bignumber.js": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", @@ -2984,11 +2847,6 @@ "fill-range": "^7.0.1" } }, - "buffer-from": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" - }, "bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -3077,17 +2935,6 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, - "concat-stream": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", - "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", - "requires": { - "buffer-from": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^2.2.2", - "typedarray": "^0.0.6" - } - }, "console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", @@ -3116,11 +2963,6 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==" }, - "core-js": { - "version": "2.6.12", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.12.tgz", - "integrity": "sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==" - }, "core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", @@ -3400,11 +3242,6 @@ "has-symbols": "^1.0.3" } }, - "get-port": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/get-port/-/get-port-3.2.0.tgz", - "integrity": "sha512-x5UJKlgeUiNT8nyo/AcnwLnZuZNcSjSw0kogRB+Whd1fjjFq4B1hySFxSFWWSn4mIBzg3sRNUDFYc4g5gjPoLg==" - }, "glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", @@ -3889,20 +3726,25 @@ } }, "mysql2": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.1.1.tgz", - "integrity": "sha512-mXz4wEj7AIKPdHQJLJcvq8GJ75BDMH9K4V8Lthra8WH7o/xjV6TXp+dXAXDaMFkLa8YhdZr5X6rxIGQSHPPfhg==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.4.1.tgz", + "integrity": "sha512-1VBrTIjDacTgcQ3/jUnMlix7twU3VfQtlAcBFPn5524AnBZcENRnpmdFt6oZaiYu4yGkAWXu0InNMg/LQs4daQ==", "requires": { "denque": "^2.1.0", "generate-function": "^2.3.1", "iconv-lite": "^0.6.3", "long": "^5.2.1", - "lru-cache": "^7.14.1", + "lru-cache": "^8.0.0", "named-placeholders": "^1.1.3", "seq-queue": "^0.0.5", "sqlstring": "^2.3.2" }, "dependencies": { + "lru-cache": { + "version": "8.0.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-8.0.5.tgz", + "integrity": "sha512-MhWWlVnuab1RG5/zMRRcVGXZLCXrZTgfwMikgzCegsPnG62yDQo5JnqKkrK4jO5iKqDAZGItAqN5CtKBCBWRUA==" + }, "sqlstring": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz", @@ -4137,14 +3979,6 @@ "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, - "promise": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz", - "integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==", - "requires": { - "asap": "~2.0.3" - } - }, "promise-inflight": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz", @@ -4240,11 +4074,6 @@ "picomatch": "^2.2.1" } }, - "regenerator-runtime": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", - "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" - }, "retry": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz", @@ -4516,25 +4345,6 @@ "has-flag": "^3.0.0" } }, - "sync-mysql": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/sync-mysql/-/sync-mysql-3.0.1.tgz", - "integrity": "sha512-EKWJFuiPRtj1s6bjSaf4tzMFeq8x0JgKtgyIsTTkD20E8pkzInEFxj1B+efbYMjQUfN9MEY3HOsaSYUmSbsUKw==", - "requires": { - "babel-runtime": "^6.18.0", - "concat-stream": "^1.6.0", - "sync-rpc": "^1.1.1", - "then-mysql": "^1.1.1" - } - }, - "sync-rpc": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/sync-rpc/-/sync-rpc-1.3.6.tgz", - "integrity": "sha512-J8jTXuZzRlvU7HemDgHi3pGnh/rkoqR/OZSjhTyyZrEkkYQbk7Z33AXp37mkPfPpfdOuj7Ex3H/TJM1z48uPQw==", - "requires": { - "get-port": "^3.1.0" - } - }, "tar": { "version": "6.1.13", "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.13.tgz", @@ -4555,16 +4365,6 @@ } } }, - "then-mysql": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/then-mysql/-/then-mysql-1.1.1.tgz", - "integrity": "sha512-QqWODY1xtWFo3XR4GllWFkXMTz+QirJKcggMETNPeGqPDcxUyApqDW5GgAUJEz4Dga3/WrXNmZY0bT+cAWjQ2g==", - "requires": { - "barrage": "^1.1.0", - "mysql": "^2.10.0", - "promise": "^7.1.1" - } - }, "to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -4602,11 +4402,6 @@ "mime-types": "~2.1.24" } }, - "typedarray": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==" - }, "undefsafe": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", @@ -4651,6 +4446,11 @@ "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==" }, + "uuid": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", + "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==" + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index c37ef08..c8b5582 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "monointegrator", - "version": "2.0.0", + "version": "2.0.1", "description": "monoIntegrator", "main": "index.js", "scripts": { @@ -25,9 +25,9 @@ "log4js": "^6.6.1", "luxon": "^3.0.1", "mysql": "^2.18.1", - "mysql2": "^3.1.1", + "mysql2": "^3.2.0", "sqlite3": "^5.1.4", - "sync-mysql": "^3.0.1" + "uuid": "^9.0.0" }, "devDependencies": { "nodemon": "^2.0.19" diff --git a/routes/.DS_Store b/routes/.DS_Store new file mode 100644 index 0000000..0998543 Binary files /dev/null and b/routes/.DS_Store differ diff --git a/routes/v1/.gitkeep b/routes/v1/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/routes/v1/echo.js b/routes/v1/echo.js new file mode 100644 index 0000000..8f11245 --- /dev/null +++ b/routes/v1/echo.js @@ -0,0 +1,17 @@ +const echo = (req, res) => { + const { id, ip, uri, method } = reqInfo(req); + + try { + + res.status(200).json({ id, ip, uri, method }); + + + } catch (err) { + log("error", `Existe un inconveniente - ${ id } :: ${ ip } :: ${ uri } :: ${ method } :: ${ err }`, "Manager"); + res.status(500).json({ msg: "Existe un inconveniente en la solicitud", id }); + } + }; + +router.all("/echo", echo); + +module.exports = router; diff --git a/server.js b/server.js index 95b0b8d..c28d445 100644 --- a/server.js +++ b/server.js @@ -11,8 +11,8 @@ global.reqInfo = reqInfo global.router = express.Router() app.use(express.json()) -app.use(helmet()) -app.use(cors({ origin: '*' })); +// app.use(helmet()) +// app.use(cors({ origin: '*' })); app.use(jsonErrorHandler) app.use(endpointMiddleware);