badmfck-api-server 1.1.3 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,7 +43,7 @@ async function Initializer(services) {
43
43
  exports.Initializer = Initializer;
44
44
  class APIService extends BaseService_1.BaseService {
45
45
  static nextLogID = 0;
46
- version = "1.2.1";
46
+ version = "1.2.2";
47
47
  options;
48
48
  netLog = [];
49
49
  constructor(options) {
@@ -128,7 +128,20 @@ class APIService extends BaseService_1.BaseService {
128
128
  headers: req.headers,
129
129
  endpoint: ep
130
130
  };
131
- const result = await i.execute(httpRequest);
131
+ let result;
132
+ try {
133
+ result = await i.execute(httpRequest);
134
+ }
135
+ catch (e) {
136
+ this.sendResponse(res, {
137
+ httpStatus: 500,
138
+ error: {
139
+ code: 10002,
140
+ message: "Internal server error"
141
+ }
142
+ }, tme, ep, log);
143
+ return;
144
+ }
132
145
  this.sendResponse(res, result, tme, ep, log);
133
146
  };
134
147
  execute();
@@ -167,6 +180,10 @@ class APIService extends BaseService_1.BaseService {
167
180
  log.response = { redirect: data.redirect };
168
181
  }
169
182
  else {
183
+ if (data.headers) {
184
+ for (let i in data.headers)
185
+ res.setHeader(i, data.headers[i]);
186
+ }
170
187
  res.statusCode = data.httpStatus ?? 200;
171
188
  if (data.rawResponse) {
172
189
  res.send(data.data);
@@ -63,6 +63,17 @@ class MysqlService extends BaseService_1.BaseService {
63
63
  .replaceAll('@fields', insertFieldNames.join(","))
64
64
  .replaceAll('@values', insertFieldValues.join(","));
65
65
  }
66
+ if (query.indexOf("@insert") !== -1) {
67
+ let oninsertNames = [];
68
+ let oninsertValues = [];
69
+ for (let i of fields) {
70
+ if (i.ignoreInInsert)
71
+ continue;
72
+ oninsertNames.push(i.name);
73
+ oninsertValues.push(i._parsedValue);
74
+ }
75
+ query = query.replaceAll("@oninsert", `(${oninsertNames.join(",")}) VALUES (${oninsertValues.join(",")})`);
76
+ }
66
77
  if (query.indexOf("@onupdate") !== -1) {
67
78
  let onUpdate = [];
68
79
  for (let i of fields) {
@@ -7,6 +7,9 @@ export interface TransferPacketVO<T> {
7
7
  httpStatus?: number;
8
8
  redirect?: string;
9
9
  rawResponse?: boolean;
10
+ headers?: {
11
+ [key: string]: string;
12
+ };
10
13
  }
11
14
  export interface HTTPRequestVO {
12
15
  raw: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",