Localhost domains are not parsed on middlewares
Link to the code that reproduces this issue
https://github.com/jackmerrill/nextjs-local-hostname-bug
To Reproduce
- Start application
- Go to both
localhost:3000andtest.localhost:3000. - 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
As an alternative, use req.headers.get("host") inside your middleware. It will return the correct host with the subdomain, if there is one.
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.
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!
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.