dimdenGD / ultimate-express

The Ultimate Express. Fastest http server with full Express compatibility, based on µWebSockets.
Apache License 2.0
518 stars 15 forks source link

Question: optimize middleware, bodyParser just for POST method? #39

Closed cesco69 closed 3 weeks ago

cesco69 commented 3 weeks ago

@dimdenGD Thanks for ultimate-express and sorry for bad english! I have just one question, I want optimize my routing resolution avoidind useless miggleware like the body parser middleware, in my case only POST method need it.

Instead of:

express.use(express.json({ limit: '100kb', strict: false }));

I have made

express.post('*', express.json({ limit: '100kb', strict: false }), (_req, _res, next) => next())

In this way

Thanks for your time!

PS. Maybe can be a performance-tips https://github.com/dimdenGD/ultimate-express?tab=readme-ov-file#performance-tips

dimdenGD commented 3 weeks ago

I think that should be faster, but probably by barely any amount, since it skips reading body for requests without it anyway.

cesco69 commented 3 weeks ago

Ok, thanks!

dimdenGD commented 3 weeks ago

Also (_req, _res, next) => next() is useless and only makes it slower

cesco69 commented 3 weeks ago

Oh right! thanks!