Troubleshooting Host Retrieval Issues in Next.js Server-Side Middleware
I have configured a wildcard domain for railway.app and deployed a Next.js application. However, when checking the host from the server-side middleware using "const host = req.headers.get('host')", I'm receiving [::1]:39107 as the host instead of the original server subdomain.domain.com host. I have also attempted to retrieve the host using "req.headers.get('x-forwarded-host')", but it returns null. How can I obtain the request origin subdomain from my server-side?
10 Replies
Project ID:
a8cb0ed9-71d4-4e5f-a4d2-0c6aeb0b8e13
a8cb0ed9-71d4-4e5f-a4d2-0c6aeb0b8e13
Solution
the host is not a header value, it is part of the http request
How can I check the subdomain from server side
Local host it is working fine
read the host value from the incoming request
Yes I am checking that using req.headers.get('host') but not getting the original host
The host is not a header value
The headers function allows you to read the HTTP incoming request headers from a Server Component.headers() can also read:
x-real-ip
x-forwarded-host
x-forwarded-port
x-forwarded-proto
the host value is not a header
🙏