badmfck-api-server 1.1.7 → 1.1.9
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",
|
@@ -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;
|
@@ -36,7 +36,8 @@ export declare class MysqlService extends BaseService {
|
|
36
36
|
reconnecting: boolean;
|
37
37
|
pool: Pool | null;
|
38
38
|
options: MysqlServiceOptions;
|
39
|
-
|
39
|
+
serviceStarted: boolean;
|
40
|
+
queries: never[];
|
40
41
|
constructor(options: MysqlServiceOptions);
|
41
42
|
static executeQuery(query: MySqlQuery | MySqlQuery[]): Promise<MysqlResult[]>;
|
42
43
|
init(): Promise<void>;
|
@@ -15,7 +15,8 @@ class MysqlService extends BaseService_1.BaseService {
|
|
15
15
|
reconnecting = false;
|
16
16
|
pool = null;
|
17
17
|
options;
|
18
|
-
|
18
|
+
serviceStarted = false;
|
19
|
+
queries = [];
|
19
20
|
constructor(options) {
|
20
21
|
super("mysql");
|
21
22
|
this.options = options;
|
@@ -23,10 +24,17 @@ class MysqlService extends BaseService_1.BaseService {
|
|
23
24
|
}
|
24
25
|
static async executeQuery(query) { return await exports.REQ_MYSQL_QUERY.request(query); }
|
25
26
|
async init() {
|
27
|
+
this.serviceStarted = false;
|
26
28
|
const ok = await this.createPool();
|
27
29
|
if (!ok) {
|
28
30
|
if (this.options.onLog)
|
29
|
-
this.options.onLog(2, "Mysql server not connected");
|
31
|
+
this.options.onLog(2, "Mysql server not connected, retrying in 3 sec");
|
32
|
+
setTimeout(() => { this.init(); }, 3000);
|
33
|
+
}
|
34
|
+
else {
|
35
|
+
this.serviceStarted = true;
|
36
|
+
if (this.options.onLog)
|
37
|
+
this.options.onLog(1, "Mysql Service started!");
|
30
38
|
}
|
31
39
|
exports.REQ_MYSQL_QUERY.listener = async (data) => {
|
32
40
|
if (!Array.isArray(data))
|
@@ -72,7 +80,7 @@ class MysqlService extends BaseService_1.BaseService {
|
|
72
80
|
oninsertNames.push(i.name);
|
73
81
|
oninsertValues.push(i._parsedValue);
|
74
82
|
}
|
75
|
-
query = query.replaceAll("@
|
83
|
+
query = query.replaceAll("@insert", `(${oninsertNames.join(",")}) VALUES (${oninsertValues.join(",")})`);
|
76
84
|
}
|
77
85
|
if (query.indexOf("@onupdate") !== -1) {
|
78
86
|
let onUpdate = [];
|
@@ -95,6 +103,8 @@ class MysqlService extends BaseService_1.BaseService {
|
|
95
103
|
return query;
|
96
104
|
}
|
97
105
|
static prepareQueryFieldValue(value, system) {
|
106
|
+
if (value === null)
|
107
|
+
return "NULL";
|
98
108
|
if (!system && typeof value === "string") {
|
99
109
|
value = value ? value.replaceAll('"', '\\"') : null;
|
100
110
|
value = '"' + value + '"';
|
@@ -120,6 +130,10 @@ class MysqlService extends BaseService_1.BaseService {
|
|
120
130
|
});
|
121
131
|
return;
|
122
132
|
}
|
133
|
+
this.pool.on("error", (evt) => {
|
134
|
+
if (this.options.onLog)
|
135
|
+
this.options.onLog(2, `${evt}`);
|
136
|
+
});
|
123
137
|
this.pool.getConnection((err, conn) => {
|
124
138
|
if (err) {
|
125
139
|
if (this.options.onLog)
|
@@ -132,6 +146,8 @@ class MysqlService extends BaseService_1.BaseService {
|
|
132
146
|
return;
|
133
147
|
}
|
134
148
|
if (!conn) {
|
149
|
+
if (this.options.onLog)
|
150
|
+
this.options.onLog(2, `NO_CONN`);
|
135
151
|
resolve({
|
136
152
|
error: {
|
137
153
|
code: "NO_CONN",
|
@@ -154,6 +170,8 @@ class MysqlService extends BaseService_1.BaseService {
|
|
154
170
|
conn.release();
|
155
171
|
}
|
156
172
|
catch (e) { }
|
173
|
+
if (this.options.onLog)
|
174
|
+
this.options.onLog(2, "QUERY_ERR " + e);
|
157
175
|
resolve({
|
158
176
|
error: {
|
159
177
|
code: "QUERY_ERR",
|
@@ -239,6 +257,7 @@ class MysqlService extends BaseService_1.BaseService {
|
|
239
257
|
this.options.onLog(2, "Can't connect to MYSQL!");
|
240
258
|
err = true;
|
241
259
|
}
|
260
|
+
2;
|
242
261
|
return new Promise((res, rej) => {
|
243
262
|
if (err) {
|
244
263
|
res(false);
|