Skip to content

How to change the express.json limit option based on the route. #3932

@marbuser

Description

@marbuser

I've got some endpoints and 90% of them I want to have a limit of around '2MB'. However, there is 1 specific route, my upload route, where I want to have an upload limit of '10MB'.

I'm using router.use and that doesn't seem to play nice.
For example, this doesn't work;

import express from 'express';

const router = express.Router();

app.use(express.json({ limit: '2MB' }));

router.use('/products', products);
router.use('/uploads', express.json({ limit: '10MB' }), uploads);

app.use('/v4', router);

I thought about making a middleware that just checks if the req.path is '/uploads', but it seems calling express.json() from a middleware causes some issue.

Not sure whether this is a bug or if I'm just being dumb, but some help would be appreciated. :)

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