Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Body already used #46

Open
manazoid opened this issue Mar 31, 2024 · 1 comment
Open

Body already used #46

manazoid opened this issue Mar 31, 2024 · 1 comment

Comments

@manazoid
Copy link

OS: WSL Ubuntu 22.04

Bun version: 1.0.36

Bunrest version: ^1.3.8

My code:

app.get("/api/v1/one/:name/:id", async (req, res) => {
  const name = req.params?.name;
  const id = req.params?.id;
  if (!id) {
    return res.status(StatusCodes.BAD_REQUEST).json({error: `No ${name} ID provided`});
  }

  const itemData = await redisClient.get(`${name}:${id}`);
  if (!itemData) {
    return res.status(StatusCodes.NOT_FOUND).json({error: `${name} not found`});
  }

  const item = JSON.parse(itemData);
  res.json({id, ...item});
}

output for every 30 minutes:

250 |       newReq.body = bodyStr
251 |     }
252 |     req.arrayBuffer;
253 |     newReq.blob = req.blob();
                        ^
error: Body already used
      at /opt/myprojectname/node_modules/bunrest/src/server/server.ts:253:19
@LuisMalhadas
Copy link
Contributor

LuisMalhadas commented May 4, 2024

second here:

router.options('/endpoint', (req, res) => {
    setCORS(res, req.headers?.origin)
    return res.status(200).send('')
})
router.post('/endpoint', async (req, res) => {
    console.log("RECEIVED", req.request.headers.get('content-type'))
    const formdata = await req.request.formData()
}
RECEIVED multipart/form-data; boundary=----WebKitFormBoundaryUfva7xqfDDwlvLFu
api-service-1  | 415 |     console.log("RECEIVED", req.request.headers.get('content-type'))
api-service-1  | 416 |     const formdata = await req.request.formData()
api-service-1  |                                  ^
api-service-1  | error: Body already used
api-service-1  |       at /app/src/Router.ts:419:28
api-service-1  |       at /app/src/Router.ts:413:36
api-service-1  |       at /app/node_modules/bunrest/src/server/server.ts:211:26
api-service-1  | POST - http://localhost:4000/endpoint failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants