badmfck-api-server 1.1.6 → 1.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,7 +16,6 @@ function getDefaultOptions() {
16
16
  baseEndPoint: '/api/',
17
17
  corsHostWhiteList: [
18
18
  'http://localhost:3000',
19
- 'http://localhost:8091',
20
19
  ],
21
20
  endpoints: [],
22
21
  jsonLimit: "10mb",
@@ -30,8 +29,8 @@ function getDefaultOptions() {
30
29
  };
31
30
  }
32
31
  exports.getDefaultOptions = getDefaultOptions;
33
- exports.REQ_CREATE_NET_LOG = new badmfck_signal_1.Req();
34
- exports.REQ_HTTP_LOG = new badmfck_signal_1.Req();
32
+ exports.REQ_CREATE_NET_LOG = new badmfck_signal_1.Req("REQ_CREATE_NET_LOG");
33
+ exports.REQ_HTTP_LOG = new badmfck_signal_1.Req("REQ_HTTP_LOG");
35
34
  async function Initializer(services) {
36
35
  for (let i of services) {
37
36
  await i.init();
@@ -49,6 +48,11 @@ class APIService extends BaseService_1.BaseService {
49
48
  constructor(options) {
50
49
  super('HTTP Service');
51
50
  this.options = options ?? getDefaultOptions();
51
+ if (!this.options.corsHostWhiteList)
52
+ this.options.corsHostWhiteList = [];
53
+ const self = "http://localhost:" + this.options.port;
54
+ if (!this.options.corsHostWhiteList.find(val => val === self))
55
+ this.options.corsHostWhiteList.push();
52
56
  }
53
57
  async init() {
54
58
  exports.REQ_HTTP_LOG.listener = async (ignore) => this.netLog;
@@ -7,7 +7,7 @@ exports.MysqlService = exports.executeQuery = exports.REQ_MYSQL_QUERY = void 0;
7
7
  const mysql_1 = __importDefault(require("mysql"));
8
8
  const BaseService_1 = require("./BaseService");
9
9
  const badmfck_signal_1 = require("badmfck-signal");
10
- exports.REQ_MYSQL_QUERY = new badmfck_signal_1.Req();
10
+ exports.REQ_MYSQL_QUERY = new badmfck_signal_1.Req("REQ_MYSQL_QUERY");
11
11
  const executeQuery = async (query) => { return await exports.REQ_MYSQL_QUERY.request(query); };
12
12
  exports.executeQuery = executeQuery;
13
13
  class MysqlService extends BaseService_1.BaseService {
@@ -26,7 +26,8 @@ class MysqlService extends BaseService_1.BaseService {
26
26
  const ok = await this.createPool();
27
27
  if (!ok) {
28
28
  if (this.options.onLog)
29
- this.options.onLog(2, "Mysql server not connected");
29
+ this.options.onLog(2, "Mysql server not connected, retrying in 3 sec");
30
+ setTimeout(() => { this.init(); }, 3000);
30
31
  }
31
32
  exports.REQ_MYSQL_QUERY.listener = async (data) => {
32
33
  if (!Array.isArray(data))
@@ -72,7 +73,7 @@ class MysqlService extends BaseService_1.BaseService {
72
73
  oninsertNames.push(i.name);
73
74
  oninsertValues.push(i._parsedValue);
74
75
  }
75
- query = query.replaceAll("@oninsert", `(${oninsertNames.join(",")}) VALUES (${oninsertValues.join(",")})`);
76
+ query = query.replaceAll("@insert", `(${oninsertNames.join(",")}) VALUES (${oninsertValues.join(",")})`);
76
77
  }
77
78
  if (query.indexOf("@onupdate") !== -1) {
78
79
  let onUpdate = [];
@@ -132,6 +133,8 @@ class MysqlService extends BaseService_1.BaseService {
132
133
  return;
133
134
  }
134
135
  if (!conn) {
136
+ if (this.options.onLog)
137
+ this.options.onLog(2, `NO_CONN`);
135
138
  resolve({
136
139
  error: {
137
140
  code: "NO_CONN",
@@ -154,6 +157,8 @@ class MysqlService extends BaseService_1.BaseService {
154
157
  conn.release();
155
158
  }
156
159
  catch (e) { }
160
+ if (this.options.onLog)
161
+ this.options.onLog(2, "QUERY_ERR " + e);
157
162
  resolve({
158
163
  error: {
159
164
  code: "QUERY_ERR",
@@ -239,6 +244,7 @@ class MysqlService extends BaseService_1.BaseService {
239
244
  this.options.onLog(2, "Can't connect to MYSQL!");
240
245
  err = true;
241
246
  }
247
+ 2;
242
248
  return new Promise((res, rej) => {
243
249
  if (err) {
244
250
  res(false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "@types/mysql": "^2.15.21",
22
22
  "axios": "^1.4.0",
23
- "badmfck-signal": "^1.2.6",
23
+ "badmfck-signal": "^1.2.7",
24
24
  "cors": "^2.8.5",
25
25
  "express": "^4.18.2",
26
26
  "mysql": "^2.18.1"