vercel / next.js

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

basePath is not included in request's URL of route handlers #62756

Open ThangHuuVu opened 8 months ago

ThangHuuVu commented 8 months ago

Link to the code that reproduces this issue

https://github.com/ThangHuuVu/reproduction-app-base-path-route-handler https://reproduction-app-base-path-route-handler.vercel.app/custom

To Reproduce

  1. Pull the reproduction. Install deps: pnpm i
  2. Start the dev server with pnpm dev
  3. Go to "http://localhost:3000/custom/hello"

Current vs. Expected behavior

Current: The req.url is returned as "http://localhost:3000/hello" Expected: It should return "http://localhost:3000/custom/hello"

Screenshot 2024-03-02 at 13 27 01

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.3.0: Wed Dec 20 21:31:00 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6020
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 20.8.0
  npm: 10.1.0
  Yarn: 1.22.21
  pnpm: 8.6.10
Relevant Packages:
  next: 14.1.1-canary.71
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

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

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

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

next dev (local), Vercel (Deployed), Other (Deployed)

Additional context

Seems that this is the behavior of pages router too. When I add a pages/api/hello2 API route, it also returns the URL without the basePath.

reaktor-yigu commented 8 months ago

Same here, it looks very severe, and so many issues are related. Is there any hacking or workaround ?

22535 #56687

56229 #60787 #60956

penguyen72 commented 1 month ago

Any updates on this?

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

penguyen72 commented 1 month ago

It seems like the basePath is included in the middleware's request. I ended up forwarding it to my route handlers