Skip to content

Commit d104fd7

Browse files
Feature: Add configuration parameter for request body size
1 parent fe1e303 commit d104fd7

File tree

7 files changed

+14
-3
lines changed

7 files changed

+14
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ For more information on our configuration manager visit its readme [here](https:
164164
- `SAS_EXPRESS_BIND_HOST`: address on which the server will be listening, defaults to `127.0.0.1`.
165165
- `SAS_EXPRESS_PORT`: port on which the server will be listening, defaults to `8080`.
166166
- `SAS_EXPRESS_KEEP_ALIVE_TIMEOUT`: Set the `keepAliveTimeout` in express.
167+
- `SAS_EXPRESS_MAX_BODY`: Set the size of request body payload, defaults to `100kb`
167168

168169
### Substrate node
169170

src/App.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
import express from 'express';
18-
import { Application, ErrorRequestHandler, Request, RequestHandler, Response } from 'express';
17+
import express, { Application, ErrorRequestHandler, Request, RequestHandler, Response } from 'express';
1918
import { Server } from 'http';
2019

2120
import packageJson from '../package.json';

src/SidecarConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class SidecarConfig {
5454
HOST: config.Get(MODULES.EXPRESS, CONFIG.BIND_HOST) as string,
5555
PORT: config.Get(MODULES.EXPRESS, CONFIG.PORT) as number,
5656
KEEP_ALIVE_TIMEOUT: config.Get(MODULES.EXPRESS, CONFIG.KEEP_ALIVE_TIMEOUT) as number,
57+
MAX_BODY: config.Get(MODULES.EXPRESS, CONFIG.MAX_BODY) as string,
5758
},
5859
SUBSTRATE: {
5960
URL: config.Get(MODULES.SUBSTRATE, CONFIG.URL) as string,

src/Specs.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ export class Specs {
8787
type: 'number',
8888
}),
8989
);
90+
91+
this._specs.appendSpec(
92+
MODULES.EXPRESS,
93+
this._specs.getSpec(CONFIG.MAX_BODY, 'Max size of request payload body. It will default to 100kb.', {
94+
default: '100kb',
95+
type: 'string',
96+
}),
97+
);
9098
}
9199

92100
/**

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async function main() {
6565

6666
startUpPrompt(config.SUBSTRATE.URL, chainName.toString(), implName.toString());
6767

68-
const preMiddlewares = [json(), middleware.httpLoggerCreate(logger)];
68+
const preMiddlewares = [json({ limit: config.EXPRESS.MAX_BODY }), middleware.httpLoggerCreate(logger)];
6969

7070
if (config.METRICS.ENABLED) {
7171
// Create Metrics App

src/types/sidecar-config/CONFIG.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ export enum CONFIG {
4141
PROM_HOST = 'PROM_HOST',
4242
LOKI_PORT = 'LOKI_PORT',
4343
INCLUDE_QUERYPARAMS = 'INCLUDE_QUERYPARAMS',
44+
MAX_BODY = 'MAX_BODY',
4445
}

src/types/sidecar-config/SidecarConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface ISidecarConfigExpress {
3737
HOST: string;
3838
PORT: number;
3939
KEEP_ALIVE_TIMEOUT: number;
40+
MAX_BODY: string;
4041
}
4142

4243
interface ISidecarConfigLog {

0 commit comments

Comments
 (0)