lwsjs / local-web-server

A lean, modular web server for rapid full-stack development.
MIT License
1.22k stars 86 forks source link

add option to increase max file size supported by body-parser #130

Closed misha-panyushkin closed 2 months ago

misha-panyushkin commented 5 years ago

Middleware error

PayloadTooLargeError: request entity too large at readStream

The transferred entity is 42Mb, so how could I increase amount of transferred data via lws config?

Error message: Middleware error PayloadTooLargeError: request entity too large at readStream (/usr/local/lib/node_modules/local-web-server/node_modules/raw-body/index.js:155:17) at executor (/usr/local/lib/node_modules/local-web-server/node_modules/raw-body/index.js:112:5) at new Promise (<anonymous>) at getRawBody (/usr/local/lib/node_modules/local-web-server/node_modules/raw-body/index.js:111:10) at /usr/local/lib/node_modules/local-web-server/node_modules/co-body/lib/json.js:41:14 at process._tickCallback (internal/process/next_tick.js:68:7)

75lb commented 5 years ago

Try omitting lws-body-parser from the stack..

if you run this command you'll see the default middleware stack (the list of middleware plugins that are active by default):

$ ws --default-stack
[
  'lws-basic-auth',
  'lws-body-parser',
  'lws-request-monitor',
  'lws-log',
  'lws-cors',
  'lws-json',
  'lws-compress',
  'lws-rewrite',
  'lws-blacklist',
  'lws-conditional-get',
  'lws-mime',
  'lws-range',
  'lws-spa',
  'lws-static',
  'lws-index'
]

To omit lws-body-parser (which i suspect is causing the issue) from the middleware stack, run this command (i skipped the lws- prefix from each plugin name - it is optional):

$ ws --stack basic-auth request-monitor log cors json compress rewrite blacklist conditional-get mime range spa static index

Let me know if that fixes the issue.

misha-panyushkin commented 5 years ago

@75lb your approach helped me, many thanks! It should be mentioned that prior to run your code, I grabbed the latest version of lws.

75lb commented 5 years ago

OK, I'm glad we isolated the issue. However, I still need to fix lws-body-parser.

I'll look into adding a new option which increases the maximum size of files supported by body-parser. Let me know if you find any other issues! 👍

misha-panyushkin commented 5 years ago

@75lb option for increasing size will be great!

P.S. It will be good to have an exclude flag for stack middleware also.

tiagostutz commented 4 years ago

Excluding flag is a great idea. And a option for increasing the limit would be nice, either.

Still needing help on this?

75lb commented 4 years ago

yes, both features are required - I will write some instructions later.. In the meantime, feel free to try some ideas!

75lb commented 2 months ago

Fixed and released in local-web-server v5.4.0