badmfck-api-server 1.9.0 → 1.9.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -26,6 +26,7 @@ export interface APIServiceOptions {
|
|
26
26
|
isProductionEnvironment: boolean;
|
27
27
|
interceptor?: IBaseEndpoint;
|
28
28
|
postproducer?: (req: HTTPRequestVO | undefined | null, res: Response, data: TransferPacketVO<any>, requestTime: number, endpoint?: string, log?: APIServiceNetworkLogItem | null) => Promise<TransferPacketVO>;
|
29
|
+
preproducer?: (req: HTTPRequestVO | undefined | null) => any;
|
29
30
|
monitor?: {
|
30
31
|
login: string;
|
31
32
|
password: string;
|
@@ -186,6 +186,17 @@ class APIService extends BaseService_1.BaseService {
|
|
186
186
|
endpoint: ep,
|
187
187
|
files: req.files ?? null
|
188
188
|
};
|
189
|
+
if (this.options.preproducer) {
|
190
|
+
try {
|
191
|
+
const preproducerResult = await this.options.preproducer(httpRequest);
|
192
|
+
if (preproducerResult)
|
193
|
+
httpRequest.preproducerResult = preproducerResult;
|
194
|
+
}
|
195
|
+
catch (e) {
|
196
|
+
this.sendResponse(res, { error: { code: 10002, message: "Internal server error", details: `${e}` }, data: null, httpStatus: 500 }, tme, ep, log, httpRequest);
|
197
|
+
return;
|
198
|
+
}
|
199
|
+
}
|
189
200
|
let result;
|
190
201
|
try {
|
191
202
|
if (!j.ignoreInterceptor) {
|
@@ -120,7 +120,7 @@ class LogService extends BaseService_1.BaseService {
|
|
120
120
|
return;
|
121
121
|
const msg = log.data[0];
|
122
122
|
const optional = log.data[1];
|
123
|
-
let text = this.createText(msg);
|
123
|
+
let text = this.createText(msg, log.level);
|
124
124
|
let source = "";
|
125
125
|
if (text.startsWith("${") && text.endsWith("}") && text.indexOf(".js") !== -1) {
|
126
126
|
source = text.substring(2, text.length - 1);
|
@@ -142,7 +142,7 @@ class LogService extends BaseService_1.BaseService {
|
|
142
142
|
showlog = true;
|
143
143
|
if (optional) {
|
144
144
|
for (let i of optional)
|
145
|
-
text += ", " + this.createText(i);
|
145
|
+
text += ", " + this.createText(i, this.level);
|
146
146
|
}
|
147
147
|
const d = new Date();
|
148
148
|
const logitem = {
|
@@ -180,7 +180,7 @@ class LogService extends BaseService_1.BaseService {
|
|
180
180
|
return "0" + num;
|
181
181
|
return num + "";
|
182
182
|
}
|
183
|
-
createText(data) {
|
183
|
+
createText(data, level) {
|
184
184
|
if (data === null)
|
185
185
|
return "null";
|
186
186
|
if (data === undefined)
|
@@ -210,7 +210,7 @@ class LogService extends BaseService_1.BaseService {
|
|
210
210
|
else {
|
211
211
|
res = data + "";
|
212
212
|
}
|
213
|
-
if (res.length > this.options.textLimit)
|
213
|
+
if (res.length > this.options.textLimit && level === LOG_LEVEL.INFO)
|
214
214
|
res = res.substring(0, this.options.textLimit) + "... (total: " + res.length + ")";
|
215
215
|
return res;
|
216
216
|
}
|