Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add configuration parameter for request body size #1565

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ For more information on our configuration manager visit its readme [here](https:
- `SAS_EXPRESS_BIND_HOST`: address on which the server will be listening, defaults to `127.0.0.1`.
- `SAS_EXPRESS_PORT`: port on which the server will be listening, defaults to `8080`.
- `SAS_EXPRESS_KEEP_ALIVE_TIMEOUT`: Set the `keepAliveTimeout` in express.
- `SAS_EXPRESS_MAX_BODY`: Set the size of request body payload, defaults to `100kb`

### Substrate node

Expand Down
3 changes: 1 addition & 2 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import express from 'express';
import { Application, ErrorRequestHandler, Request, RequestHandler, Response } from 'express';
import express, { Application, ErrorRequestHandler, Request, RequestHandler, Response } from 'express';
import { Server } from 'http';

import packageJson from '../package.json';
Expand Down
1 change: 1 addition & 0 deletions src/SidecarConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class SidecarConfig {
HOST: config.Get(MODULES.EXPRESS, CONFIG.BIND_HOST) as string,
PORT: config.Get(MODULES.EXPRESS, CONFIG.PORT) as number,
KEEP_ALIVE_TIMEOUT: config.Get(MODULES.EXPRESS, CONFIG.KEEP_ALIVE_TIMEOUT) as number,
MAX_BODY: config.Get(MODULES.EXPRESS, CONFIG.MAX_BODY) as string,
},
SUBSTRATE: {
URL: config.Get(MODULES.SUBSTRATE, CONFIG.URL) as string,
Expand Down
8 changes: 8 additions & 0 deletions src/Specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ export class Specs {
type: 'number',
}),
);

this._specs.appendSpec(
MODULES.EXPRESS,
this._specs.getSpec(CONFIG.MAX_BODY, 'Max size of request payload body. It will default to 100kb.', {
default: '100kb',
type: 'string',
}),
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async function main() {

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

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

if (config.METRICS.ENABLED) {
// Create Metrics App
Expand Down
1 change: 1 addition & 0 deletions src/types/sidecar-config/CONFIG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ export enum CONFIG {
PROM_HOST = 'PROM_HOST',
LOKI_PORT = 'LOKI_PORT',
INCLUDE_QUERYPARAMS = 'INCLUDE_QUERYPARAMS',
MAX_BODY = 'MAX_BODY',
}
1 change: 1 addition & 0 deletions src/types/sidecar-config/SidecarConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface ISidecarConfigExpress {
HOST: string;
PORT: number;
KEEP_ALIVE_TIMEOUT: number;
MAX_BODY: string;
}

interface ISidecarConfigLog {
Expand Down
Loading