badmfck-api-server 1.8.7 → 1.8.9
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.
@@ -25,6 +25,7 @@ export interface APIServiceOptions {
|
|
25
25
|
onError?: ((...rest: any[]) => void) | null;
|
26
26
|
isProductionEnvironment: boolean;
|
27
27
|
interceptor?: IBaseEndpoint;
|
28
|
+
postproducer?: (packet: TransferPacketVO) => Promise<TransferPacketVO>;
|
28
29
|
monitor?: {
|
29
30
|
login: string;
|
30
31
|
password: string;
|
@@ -49,5 +50,5 @@ export declare class APIService extends BaseService {
|
|
49
50
|
netLog: APIServiceNetworkLogItem[];
|
50
51
|
constructor(options?: APIServiceOptions | null);
|
51
52
|
init(): Promise<void>;
|
52
|
-
sendResponse(res: Response, data: TransferPacketVO<any>, requestTime: number, endpoint?: string, log?: APIServiceNetworkLogItem | null): void
|
53
|
+
sendResponse(res: Response, data: TransferPacketVO<any>, requestTime: number, endpoint?: string, log?: APIServiceNetworkLogItem | null): Promise<void>;
|
53
54
|
}
|
@@ -57,7 +57,7 @@ async function Initializer(services) {
|
|
57
57
|
exports.Initializer = Initializer;
|
58
58
|
class APIService extends BaseService_1.BaseService {
|
59
59
|
static nextLogID = 0;
|
60
|
-
version = "1.8.
|
60
|
+
version = "1.8.9";
|
61
61
|
options;
|
62
62
|
monitor;
|
63
63
|
monitorIndexFile;
|
@@ -277,16 +277,24 @@ class APIService extends BaseService_1.BaseService {
|
|
277
277
|
(0, LogService_1.logCrit)('${APIService.js}', 'API Service started at: ' + this.options.port + ", with base endpoint:" + this.options.baseEndPoint + ", ver.: " + this.version);
|
278
278
|
});
|
279
279
|
}
|
280
|
-
sendResponse(res, data, requestTime, endpoint, log) {
|
280
|
+
async sendResponse(res, data, requestTime, endpoint, log) {
|
281
|
+
if (this.options.postproducer) {
|
282
|
+
try {
|
283
|
+
data = await this.options.postproducer({ ...data });
|
284
|
+
}
|
285
|
+
catch (e) {
|
286
|
+
(0, LogService_1.logError)("Postproducer error", e);
|
287
|
+
}
|
288
|
+
}
|
281
289
|
data.responseTime = (+new Date()) - requestTime;
|
282
290
|
data.core = this.version;
|
283
291
|
data.endpoint = endpoint ?? "no_endpoint";
|
284
292
|
if (this.options.appVersion)
|
285
293
|
data.version = this.options.appVersion;
|
286
|
-
if (this.monitor)
|
287
|
-
this.monitor.registrateResponse(data.endpoint, data.responseTime);
|
288
294
|
if (log)
|
289
295
|
log.time = data.responseTime;
|
296
|
+
if (this.monitor)
|
297
|
+
this.monitor.registrateResponse(data.endpoint, data.responseTime);
|
290
298
|
if (res.destroyed || res.closed) {
|
291
299
|
if (log)
|
292
300
|
log.error = "Connection already closed, can't send response for: " + data.endpoint;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "badmfck-api-server",
|
3
|
-
"version": "1.8.
|
3
|
+
"version": "1.8.9",
|
4
4
|
"description": "Simple API http server based on express",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -20,13 +20,13 @@
|
|
20
20
|
"@types/express-fileupload": "^1.5.0",
|
21
21
|
"@types/mysql": "^2.15.21",
|
22
22
|
"@types/ws": "^8.5.9",
|
23
|
-
"axios": "^1.
|
23
|
+
"axios": "^1.7.2",
|
24
24
|
"badmfck-signal": "^1.4.5",
|
25
25
|
"cors": "^2.8.5",
|
26
26
|
"express": "^4.19.2",
|
27
27
|
"express-fileupload": "^1.5.0",
|
28
28
|
"mysql": "^2.18.1",
|
29
|
-
"ws": "^8.
|
29
|
+
"ws": "^8.17.0"
|
30
30
|
},
|
31
31
|
"devDependencies": {
|
32
32
|
"@types/cors": "^2.8.13",
|