vercel / vercel/next.js

Next uses invalid URL behind proxy

Open
#63,402 4 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug not stale
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/apfelbox/reproducer-invalid-next-host

To Reproduce
  1. Run pnpm dev
  2. Open http://localhost:3000
  3. Open the same URL via a reverse proxy.
Current vs. Expected behavior

The internal URL (in request.url and request.nextUrl) should use the correct and proper URL, as otherwise we can't use it for anything output related. We can't just generate an URL, as it will be generated with localhost:3000.

Screenshot_2024-03-18_10 23 23

Provide environment information
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000
Binaries:
  Node: 18.19.0
  npm: 10.2.3
  Yarn: N/A
  pnpm: 8.15.5
Relevant Packages:
  next: 14.1.3
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.2
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

App Router

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

next dev (local), next start (local)

Additional context

No response

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 linked reproducer and run pnpm dev, checking request.url and request.nextUrl both directly and through a reverse proxy. Trace how the App Router constructs these URLs in next dev and next start. Done means both values use the proper proxied URL instead of localhost:3000.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs
Domain
backend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.