R
Railway8mo ago
Xmahbub

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?
Solution:
the host is not a header value, it is part of the http request
Jump to solution
10 Replies
Percy
Percy8mo ago
Project ID: a8cb0ed9-71d4-4e5f-a4d2-0c6aeb0b8e13
Xmahbub
XmahbubOP8mo ago
a8cb0ed9-71d4-4e5f-a4d2-0c6aeb0b8e13
Solution
Brody
Brody8mo ago
the host is not a header value, it is part of the http request
Xmahbub
XmahbubOP8mo ago
How can I check the subdomain from server side Local host it is working fine
Brody
Brody8mo ago
read the host value from the incoming request
Xmahbub
XmahbubOP8mo ago
Yes I am checking that using req.headers.get('host') but not getting the original host
Brody
Brody8mo ago
The host is not a header value
Xmahbub
XmahbubOP8mo ago
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
Brody
Brody8mo ago
the host value is not a header
Xmahbub
XmahbubOP8mo ago
🙏
Want results from more Discord servers?
Add your server