badmfck-api-server 1.1.2 → 1.1.4

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);
@@ -38,6 +38,7 @@ export declare class MysqlService extends BaseService {
38
38
  options: MysqlServiceOptions;
39
39
  retries: number;
40
40
  constructor(options: MysqlServiceOptions);
41
+ static executeQuery(query: MySqlQuery | MySqlQuery[]): Promise<MysqlResult[]>;
41
42
  init(): Promise<void>;
42
43
  onApplicationReady(): Promise<void>;
43
44
  static prepareQuery(query: string, fields: MysqlQueryField[]): string;
@@ -21,6 +21,7 @@ class MysqlService extends BaseService_1.BaseService {
21
21
  this.options = options;
22
22
  this.init();
23
23
  }
24
+ static async executeQuery(query) { return await exports.REQ_MYSQL_QUERY.request(query); }
24
25
  async init() {
25
26
  const ok = await this.createPool();
26
27
  if (!ok) {
@@ -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.2",
3
+ "version": "1.1.4",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",