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

Canary: POST to API-routes hang when using middleware #34966

Closed
1 task done
kevineinarsson opened this issue Mar 2, 2022 · 2 comments · Fixed by #35131
Closed
1 task done

Canary: POST to API-routes hang when using middleware #34966

kevineinarsson opened this issue Mar 2, 2022 · 2 comments · Fixed by #35131
Labels
Middleware Related to Next.js Middleware.

Comments

@kevineinarsson
Copy link

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

    Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP Wed Aug 25 23:20:18 UTC 2021
    Binaries:
      Node: 16.14.0
      npm: 8.3.1
      Yarn: 1.22.17
      pnpm: N/A
    Relevant packages:
      next: 12.1.1-canary.5
      react: 17.0.2
      react-dom: 17.0.2

What browser are you using? (if relevant)

cURL

How are you deploying your application? (if relevant)

next start

Describe the Bug

When using a middleware, POST requests to API-routes never resolve. Commenting out the code added to next-server.ts from #34519 solves the issue. GET works as expected.

Apologies if this is a known issue, thought it would be good to bring up otherwise.

Sidenote: When setting config.api.bodyParser: false on API-routes, won't they still have been replaced in the middleware layer, or is it completely separate?

Expected Behavior

POST requests to api-routes to work.

To Reproduce

https://stackblitz.com/edit/nextjs-hhf3gk

@kevineinarsson kevineinarsson added the bug Issue was opened via the bug report template. label Mar 2, 2022
@balazsorban44
Copy link
Member

Confirmed, I created this super minimal reproduction as well: https://github.com/balazsorban44/nextjs-34966

[email protected] and up causes the issue, which corresponds with your observation about #34519

@balazsorban44 balazsorban44 added Middleware Related to Next.js Middleware. kind: bug and removed bug Issue was opened via the bug report template. labels Mar 3, 2022
@kodiakhq kodiakhq bot closed this as completed in #35131 Mar 8, 2022
kodiakhq bot pushed a commit that referenced this issue Mar 8, 2022
fixes #34966

Wait for reading original request body before overwriting the request properties with `originalBody?.finalize()` call since it caused the problem when middleware does not read request body

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Middleware Related to Next.js Middleware.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants