badmfck-api-server 1.8.8 → 1.8.9
Sign up to get free protection for your applications and to get access to all the features.
@@ -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;
|