Skip to content

Commit 5855bd3

Browse files
feat: add possibility to config json middleware
1 parent 8823c8f commit 5855bd3

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/interfaces/services/i-gateway.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { OptionsJson } from 'body-parser';
12
import type { Express, Request } from 'express';
23
import type { IMicroserviceRequest } from '@interfaces/core/i-microservice-request';
34
import type {
@@ -12,6 +13,7 @@ interface IGatewayOptions extends IAbstractMicroserviceOptions {
1213
reqTimeout: number;
1314
hasAutoRegistration: boolean;
1415
batchLimit: number;
16+
jsonParams: OptionsJson;
1517
}
1618

1719
interface IGatewayParams extends IAbstractMicroserviceParams {

src/services/gateway.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Gateway extends AbstractMicroservice {
3535
reqTimeout: 1000 * 15, // 15 seconds
3636
hasAutoRegistration: true, // auto registration microservices
3737
batchLimit: 5,
38+
jsonParams: {},
3839
};
3940

4041
/**
@@ -66,12 +67,12 @@ class Gateway extends AbstractMicroservice {
6667
this.init(options, params);
6768

6869
const { beforeRoute, afterRoute } = params;
69-
const { listener } = this.options;
70+
const { listener, jsonParams } = this.options;
7071
const [, ...route] = listener.split('/');
7172

7273
this.express.disable('x-powered-by');
7374
// Parse JSON body request
74-
this.express.use(express.json());
75+
this.express.use(express.json(jsonParams));
7576
beforeRoute?.(this.express);
7677
// Set gateway request listener
7778
this.express.post(`/${route.join('/')}`, this.handleClientRequest.bind(this));

0 commit comments

Comments
 (0)