vercel / vercel/next.js

"trailingSlash" causing CORS errors

Open
#66,352 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/tippfelher/nextjs-redirect-issue

To Reproduce

Open https://nextjs-permanent-redirect-issue.vercel.app/something
The response header correctly contains Access-Control-Allow-Origin: *

Open https://nextjs-permanent-redirect-issue.vercel.app/something/
The response header contains no Access-Control-Allow-Origin: *

Current vs. Expected behavior

Open https://nextjs-permanent-redirect-issue.vercel.app/something/
The response header also contains Access-Control-Allow-Origin: *

Configuring https://nextjs.org/docs/pages/api-reference/next-config-js/trailingSlash is obviously no solution.

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

Not sure

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

Vercel (Deployed), Other (Deployed)

Additional context

Repo for reproduction: https://github.com/tippfelher/nextjs-redirect-issue

  1. Added route (/src/app/something/route.ts)
  2. Added headers in nextjs.config.js

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction repository and inspect src/app/something/route.ts and nextjs.config.js, then compare the deployed responses for /something and /something/. The fix is complete when both responses include Access-Control-Allow-Origin: *; verify against the linked deployment URLs.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.