egg.js post数据过大时报错的处理,报出413:Payload Too Large,设置bodyparser

加500行埋点是不是会占用你一天的时间而且很容易犯错,如果你想只用一小时准确加完这500行埋点剩下一天喝茶聊天来试试这520工具,高效加埋点,目前我们公司100号前端都在用

http://www.520webtool.com/

自己开发所以免费,里面有使用视频

可以通过配置来设置大小,修改配置文件:

  exports.bodyParser = {
    jsonLimit: '5mb',
    formLimit: '6mb',
  };
默认配置:

/**
   * The option of `bodyParser` middleware
   *
   * @member Config#bodyParser
   * @property {Boolean} enable - enable bodyParser or not, default is true
   * @property {String | RegExp | Function | Array} ignore - won't parse request body when url path hit ignore pattern, can not set `ignore` when `match` presented
   * @property {String | RegExp | Function | Array} match - will parse request body only when url path hit match pattern
   * @property {String} encoding - body's encoding type,default is utf8
   * @property {String} formLimit - limit of the urlencoded body. If the body ends up being larger than this limit, a 413 error code is returned. Default is 100kb
   * @property {String} jsonLimit - limit of the json body, default is 100kb
   * @property {Boolean} strict - when set to true, JSON parser will only accept arrays and objects. Default is true
   * @property {Number} queryString.arrayLimit - urlencoded body array's max length, default is 100
   * @property {Number} queryString.depth - urlencoded body object's max depth, default is 5
   * @property {Number} queryString.parameterLimit - urlencoded body maximum parameters, default is 1000
   */
  config.bodyParser = {
    enable: true,
    encoding: 'utf8',
    formLimit: '100kb',
    jsonLimit: '100kb',
    strict: true,
    // @see https://github.com/hapijs/qs/blob/master/lib/parse.js#L8 for more options
    queryString: {
      arrayLimit: 100,
      depth: 5,
      parameterLimit: 1000,
    },
  };
可以查找 egg.js 文档中的 

config.bodyParser
————————————————
版权声明:本文为CSDN博主「bigsea622」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/bigsea622/article/details/86287548

发布了134 篇原创文章 · 获赞 401 · 访问量 162万+

猜你喜欢

转载自blog.csdn.net/sd19871122/article/details/103921806