tsndr / cloudflare-worker-router

A super lightweight router (1.0K) with middleware support and ZERO dependencies for Cloudflare Workers.
MIT License
227 stars 30 forks source link

When using middleware how do you use the body multiple times in each middleware? #31

Closed kalepail closed 8 months ago

kalepail commented 11 months ago

I'm getting the error Body has already been used. It can only be used once. Use tee() first if you need to read it twice.

Normally you'd use req.clone or res.clone but clone doesn't appear to exist on req or res for this library.

tsndr commented 9 months ago

I've added some tests for this behavior, and they pass, can you please retest with the current version v3.3.4?

Tests: https://github.com/tsndr/cloudflare-worker-router/blob/306c046adb3fed3dbdd4df0787476edf001539fa/tests/index.spec.ts#L296-L365