node.js - Express: limit request size -


to limit request size 123 bytes, use following works fine:

app.use(bodyparser.urlencoded({     extended: true,     limit: 123 })); 

to parse requests except for "/specialrequest", use following works fine well:

app.use(/^(?!\/specialrequest)/,bodyparser.urlencoded({     extended: true })); 

but fail limit request size of all requests 123 , parse requests except for "/specialrequest". here current code:

app.use(/^(?!\/specialrequest)/,bodyparser.urlencoded({     extended: true,     limit: 123 })); 

however, limits requests size requests different "/specialrequest". how can limit request size of all requests 123 , parse requests except for "/specialrequest"?

if want request body /specialrequest limited in size not parsed, can use bodyparser.raw(). in case, req.body buffer instance contains request body as-is (unparsed, although inflated if presented gzipped or deflated data; behaviour can disabled through options).

you need declare before insert bodyparser.urlencoded() middleware:

app.post('/specialrequest', bodyparser.raw({ limit : 123, type : '*/*' }), function(req, res) {   ... });  app.use(bodyparser.urlencoded({     extended: true,     limit: 123 })); 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -