next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Localhost domains are not parsed on middlewares

Open tessamerrill opened this issue 2 years ago • 2 comments

Link to the code that reproduces this issue

https://github.com/jackmerrill/nextjs-local-hostname-bug

To Reproduce

  1. Start application
  2. Go to both localhost:3000 and test.localhost:3000.
  3. Record the logged output in the Next.js console

Current vs. Expected behavior

Current: Logs localhost:3000 localhost

Expected: Logs test.localhost:3000 test.localhost

The NextRequest.nextUrl.host and NextRequest.nextUrl.hostname should track subdomains on localhost (such as for testing on multi-tenant applications).

Verify canary release

  • [X] I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sat, 23 Sep 2023 22:55:13 +0000
Binaries:
  Node: 20.8.0
  npm: 10.1.0
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 13.5.4-canary.9
  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)

Middleware / Edge (API routes, runtime)

Additional context

No response

tessamerrill avatar Oct 02 '23 19:10 tessamerrill

As an alternative, use req.headers.get("host") inside your middleware. It will return the correct host with the subdomain, if there is one.

TotomInc avatar Dec 17 '23 16:12 TotomInc

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

nextjs-bot avatar Jun 14 '25 23:06 nextjs-bot

This issue has been automatically closed due to two years of inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding!

nextjs-bot avatar Jun 22 '25 23:06 nextjs-bot

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.

github-actions[bot] avatar Jul 07 '25 00:07 github-actions[bot]