Troubleshooting Host Retrieval Issues in Next.js Server-Side Middleware

xmahbubHOBBY

a year ago

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?

0 Replies

xmahbubHOBBY

a year ago

a8cb0ed9-71d4-4e5f-a4d2-0c6aeb0b8e13


a year ago

the host is not a header value, it is part of the http request


xmahbubHOBBY

a year ago

How can I check the subdomain from server side


xmahbubHOBBY

a year ago

Local host it is working fine


a year ago

read the host value from the incoming request


xmahbubHOBBY

a year ago

Yes I am checking that using req.headers.get('host') but not getting the original host


a year ago

The host is not a header value


xmahbubHOBBY

a year 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


a year ago

the host value is not a header


xmahbubHOBBY

a year ago

🙏