vercel / vercel/next.js

request host header is [::]:3000 in middleware when redirecting in server action

Open
#62,903 21 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Middleware Redirects
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/kevinmitch14/redirects

To Reproduce
  1. Start application npm run build + start
  2. Press submit button to trigger redirect
  3. View console logs
Current vs. Expected behavior

Current: request host header is [::]:3000
Expected: request host header is localhost:3000

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
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 20.9.0
  npm: 10.1.0
  Yarn: 1.22.19
  pnpm: 8.15.1
Relevant Packages:
  next: 14.2.0-canary.0 // Latest available version is detected (14.2.0-canary.0).
  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), next build (local)

Additional context

Host looks to be okay when deployed to Vercel. However I wasn't able to test this with subdomains.

I've tracked it down to this PR https://github.com/vercel/next.js/pull/62561. Using the canary version before this logs host as localhost:3000.

For context, our app is a multi tenant app, each tenant lives on a subdomain. We use rewrites to handle this. To get the subdomain, we use the request host header.

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

Reproduce the issue in the linked redirects repository by running npm run build and start, submitting the form, and inspecting the middleware console output. Compare the host behavior with the canary version before PR 62561; done means local redirects report the expected localhost:3000 host while retaining the reported tenant-host behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, react
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.