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

NextJS server is intercepting POST requests that _should_ be handled by rewrites, and treating them as GET #65626

Open
etnichols opened this issue May 10, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template. Navigation Related to Next.js linking (e.g., <Link>) and navigation. Pages Router Related to Pages Router.

Comments

@etnichols
Copy link

Link to the code that reproduces this issue

https://github.com/etnichols/nextjs-rewrite-bug-repro

To Reproduce

  1. clone repro repo: https://github.com/etnichols/nextjs-rewrite-bug-repro.
  2. npm i
  3. npm run dev
  4. Server will be up and running on localhost:3000. The server exposes a single page at /checkout/billing/[id].
  5. In the browser, visit localhost:3000/checkout/billing/1234 and observe the following page is rendered as expected:
    Screenshot 2024-05-10 at 3 50 43 PM
  6. Using the CLI, perform a POST request to the same endpoint:
$ curl -H 'Content-Type: application/json' \
-d '{ "title":"foo","body":"bar", "id": 1}' \
-X POST \
http://localhost:3000/billing/1234
  1. Observe that the server returns HTML as a response to the POST, when it should instead be using the rewrite fallback block defined in next.config.mjs.

Current vs. Expected behavior

The NextJS server is treating POST requests to endpoints as GET requests, and incorrectly serves back HTML to the POST request, instead of either 1) using the next js fallback rewrite config or 2) simply returning a 404.

Expected behavior: given a POST request to some NextJS server which does not have an API route configured, appropriately using rewrite config, or return a 404.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.1.0: Mon Oct  9 21:28:45 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6020
  Available memory (MB): 16384
  Available CPU cores: 12
Binaries:
  Node: 18.17.1
  npm: 9.6.7
  Yarn: N/A
  pnpm: 8.7.6
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: 14.2.3
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Navigation, Pages Router

Which stage(s) are affected? (Select all that apply)

next dev (local), Vercel (Deployed)

Additional context

We have a production app exhibiting this behavior as well.

@etnichols etnichols added the bug Issue was opened via the bug report template. label May 10, 2024
@github-actions github-actions bot added Navigation Related to Next.js linking (e.g., <Link>) and navigation. Pages Router Related to Pages Router. labels May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Navigation Related to Next.js linking (e.g., <Link>) and navigation. Pages Router Related to Pages Router.
Projects
None yet
Development

No branches or pull requests

1 participant