vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.23k stars 27.02k forks source link

Route Handler has CORS errors if GET is not present #57999

Closed C-3-F closed 8 months ago

C-3-F commented 1 year ago

Link to the code that reproduces this issue

https://github.com/C-3-F/nextjs13-cors-bug-example

To Reproduce

Start both the client and server by using the above commands.

In the request payload box, type some sample JSON. The requests will just take that request and return it.

The 'works' box will return the payload with a 200.

The 'doesntwork' box will fail the request with a CORS error.

Current vs. Expected behavior

The expected behavior is that Global CORS headers set in next-config.js should be applied to all request method types.

Current behavior is that if you have a POST method alone, the CORS headers are not set. If you add a GET method to the same route, then the POST request magically works.

Verify canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.6.0: Fri Sep 15 13:41:30 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T8103
Binaries:
  Node: 20.7.0
  npm: 10.1.0
  Yarn: 1.22.19
  pnpm: 8.7.6
Relevant Packages:
  next: 14.0.2-canary.10
  eslint-config-next: 13.4.19
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

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

App Router, Middleware / Edge (API routes, runtime)

Additional context

I'm pretty sure this issue was introduced with the App router. I haven't been able to get it to work with any versions ^13.4. I'm also using the Brave browser. But also tested in Chrome which is broken too.

NEXT-2810

samcx commented 11 months ago

@C-3-F Thank you for sharing! Taking a look :frog-eyes:

tomelliot commented 8 months ago

@samcx just to confirm - this hasn't been addressed yet has it?

samcx commented 8 months ago

@tomelliot Looks like this slipped! Taking a look again :frog-eyes:

tomelliot commented 8 months ago

Resolved by https://github.com/vercel/next.js/pull/63264

Thanks @samcx !

github-actions[bot] commented 8 months ago

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