badmfck-api-server 1.9.0 → 1.9.2

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) {
@@ -25,6 +25,7 @@ export interface HTTPRequestVO<T = any> {
25
25
  };
26
26
  endpoint: string;
27
27
  interceptorResult?: TransferPacketVO<any>;
28
+ preproducerResult?: any;
28
29
  precheck?: TransferPacketVO<any> | null;
29
30
  files: FileArray | null | undefined;
30
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",