Testing procedure:
- Create a new worker using the workers-tinygo template.
- Run the worker locally.
- Run curl -X POST -d "data" http://127.0.0.1:8787/echo .
- The below error will be seen:
TypeError: Body has already been used. It can only be used once. Use tee() first if you need to read it twice.
at async Object.fetch (file:///c:/project_folder/node_modules/miniflare/dist/src/workers/core/entry.worker.js:4323:22)
Expected result should be:
data
workers-go main.go /echo API has no such error, the code difference is as below:
workers-go:
b, err := io.ReadAll(req.Body)
if err != nil {
panic(err)
}
io.Copy(w, bytes.NewReader(b))
workers-tinygo:
Either apply the same change from workers-go or make use of below worked:
r := io.TeeReader(req.Body, w)
io.ReadAll(r)