@bee.js/node 0.0.78 → 0.0.80
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/lib/ORM/beeORM.js +17 -1
- package/lib/beeHive/headers.js +19 -10
- package/package.json +1 -1
package/lib/ORM/beeORM.js
CHANGED
|
@@ -136,6 +136,7 @@ module.exports = {
|
|
|
136
136
|
|
|
137
137
|
// TODO pegar dinamicamnete database utilizada
|
|
138
138
|
let db = configs.databases.default;
|
|
139
|
+
let pool;
|
|
139
140
|
|
|
140
141
|
switch (db.type) {
|
|
141
142
|
case "mssql": // TODO implementar na versao >=1.2
|
|
@@ -143,11 +144,12 @@ module.exports = {
|
|
|
143
144
|
case "mongo": // TODO implementar na versao >=1.2
|
|
144
145
|
return false;
|
|
145
146
|
default:
|
|
146
|
-
|
|
147
|
+
pool = mysql.createPool({
|
|
147
148
|
acquireTimeout: 10000, // Tempo limite para tentar adquirir uma nova conexão
|
|
148
149
|
connectTimeout: 10000, // Tempo limite para conectar ao banco de dados
|
|
149
150
|
idleTimeout: 60000, // Tempo que uma conexão pode ficar inativa antes de ser fechada
|
|
150
151
|
reconnect: true,
|
|
152
|
+
enableKeepAlive: true,
|
|
151
153
|
...db,
|
|
152
154
|
host: db.host,
|
|
153
155
|
user: db.user,
|
|
@@ -157,6 +159,20 @@ module.exports = {
|
|
|
157
159
|
connectionLimit: db.connectionLimit || 10,
|
|
158
160
|
queueLimit: db.queueLimit || 0,
|
|
159
161
|
});
|
|
162
|
+
|
|
163
|
+
if (db.ping)
|
|
164
|
+
setInterval(async () => {
|
|
165
|
+
console.log("ping db");
|
|
166
|
+
try {
|
|
167
|
+
const connection = await pool.getConnection();
|
|
168
|
+
await connection.ping();
|
|
169
|
+
connection.release();
|
|
170
|
+
} catch (error) {
|
|
171
|
+
console.error("MySQL ping error:", { error });
|
|
172
|
+
}
|
|
173
|
+
}, db.ping);
|
|
174
|
+
|
|
175
|
+
return pool;
|
|
160
176
|
}
|
|
161
177
|
},
|
|
162
178
|
|
package/lib/beeHive/headers.js
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
module.exports = function(req, res, next) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
module.exports = function (req, res, next) {
|
|
2
|
+
// TODO otimizar e buscar do config.
|
|
3
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
4
|
+
res.setHeader(
|
|
5
|
+
"Access-Control-Allow-Methods",
|
|
6
|
+
"GET, POST, OPTIONS, PUT, PATCH, DELETE"
|
|
7
|
+
);
|
|
8
|
+
res.setHeader(
|
|
9
|
+
"Access-Control-Allow-Headers",
|
|
10
|
+
"Origin, Referer, X-Requested-With, Content-Type, Accept, Authorization"
|
|
11
|
+
);
|
|
12
|
+
res.setHeader("Access-Control-Allow-Credentials", true);
|
|
13
|
+
res.setHeader("Content-Type", "application/json");
|
|
14
|
+
|
|
15
|
+
// Evita cache pela Cloudflare e outros proxies
|
|
16
|
+
res.setHeader("Cache-Control", "no-store");
|
|
17
|
+
|
|
18
|
+
next();
|
|
19
|
+
};
|