@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 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
- return mysql.createPool({
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
 
@@ -1,10 +1,19 @@
1
- module.exports = function(req, res, next) {
2
- // TODO otimizar e buscar do config.
3
- res.setHeader('Access-Control-Allow-Origin', '*');
4
- res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
5
- res.setHeader("Access-Control-Allow-Headers", "Origin, Referer, X-Requested-With, Content-Type, Accept, Authorization");
6
- res.setHeader('Access-Control-Allow-Credentials', true);
7
- res.setHeader('Content-Type', 'application/json');
8
-
9
- next();
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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bee.js/node",
3
- "version": "0.0.78",
3
+ "version": "0.0.80",
4
4
  "description": "A JavaScript framework for making Node.js API´s",
5
5
  "main": "index.js",
6
6
  "scripts": {