Error: request entity too large

后端 未结 21 3464
无人共我
无人共我 2020-11-22 06:36

I\'m receiving the following error with express:

Error: request entity too large
    at module.exports (/Users/michaeljames/Documents/Projects/Proj/mean/node         


        
21条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 07:03

    Little old post but I had the same problem

    Using express 4.+ my code looks like this and it works great after two days of extensive testing.

    var url         = require('url'),
        homePath    = __dirname + '/../',
        apiV1       = require(homePath + 'api/v1/start'),
        bodyParser  = require('body-parser').json({limit:'100mb'});
    
    module.exports = function(app){
        app.get('/', function (req, res) {
            res.render( homePath + 'public/template/index');
        });
    
        app.get('/api/v1/', function (req, res) {
            var query = url.parse(req.url).query;
            if ( !query ) {
                res.redirect('/');
            }
            apiV1( 'GET', query, function (response) {
                res.json(response);
            });
        });
    
        app.get('*', function (req,res) {
            res.redirect('/');
        });
    
        app.post('/api/v1/', bodyParser, function (req, res) {
            if ( !req.body ) {
                res.json({
                    status: 'error',
                    response: 'No data to parse'
                });
            }
            apiV1( 'POST', req.body, function (response) {
                res.json(response);
            });
        });
    };
    

提交回复
热议问题