Skip to content
This repository was archived by the owner on Mar 7, 2020. It is now read-only.
This repository was archived by the owner on Mar 7, 2020. It is now read-only.

Body parser default ContentLength limit #14

@sberryman

Description

@sberryman

While it would be nice if all JSON payloads were under 100KB, that won't be the case 100% of the time.

Express 4 uses the body-parser package to decode JSON and Raw payloads which is nice but the default is a bit small for my use case.

The template loads the body-parser package here:
https://github.com/openfaas-incubator/node8-express-template/blob/master/template/node8-express/index.js#L12

app.use(bodyParser.json());

The parser accepts an options object, one of those options is limit which is a string parsed by the bytes package or a number of bytes. Body parser parses the limit option using the following code:

var limit = typeof opts.limit !== 'number'
    ? bytes.parse(opts.limit || '100kb')
    : opts.limit

If you decide to only implement the bytes parser (easy option) it could be a very simple change:

app.use(bodyParser.json({ limit: process.env.BODYPARSER_JSON_LIMIT }));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions