R
Railwayβ€’7mo ago
kevin

request headers host unexpectedly changed

Our app broke just now (today). We're a platform that allows users to set up subdomains, and we handle loading by checking the request host header, for the subdomain (or custom domain). However, this is what we're getting for the request host header now, to our nextjs app:
[::1]:33155
[::1]:33155
Previously we got something like "subdomain.example.com", and now it's just a port it looks like. Will the host header just be unuseable from now on, or will it be fixed? Thanks! πŸ™
No description
19 Replies
Percy
Percyβ€’7mo ago
Project ID: 63b7280d-bfb7-499f-89d2-73fd8e2a081b
kevin
kevinβ€’7mo ago
63b7280d-bfb7-499f-89d2-73fd8e2a081b ^ screenshot is with req.headers.host (req: NextApiRequest) also tried req.headers["x-forwarded-host"], but just got undefined unfortunately
Brody
Brodyβ€’7mo ago
looks like youre printing the local host, the external host is still passed by railway https://utilities.up.railway.app/raw
kevin
kevinβ€’7mo ago
hm im not sure why - i also just noticed this issue after deploying our app (cause we also do sanity testing after deploys) is https://utilities.up.railway.app/raw a test app? like does it get frequently deployed i wonder - just throwing out questions, since we didn't change any part of our code here at all with header host checking, and suddenly it breaks today
Brody
Brodyβ€’7mo ago
of course i have covered my bases, redeployed 5 minutes ago and if youre thinking this is an issue with custom domains, theres this too https://subdomain.overr.net/raw
kevin
kevinβ€’7mo ago
gotcha.. yea im not sure, why this is suddenly happening, this is what im running:
const host = req.headers.host;
const forwardedHost = req.headers["X-Forwarded-Host"];
const referer = req.headers.referer;
console.log({ host, forwardedHost, referer });
const host = req.headers.host;
const forwardedHost = req.headers["X-Forwarded-Host"];
const referer = req.headers.referer;
console.log({ host, forwardedHost, referer });
very tame, and this is what im getting back now,
{
host: '[::1]:44943',
forwardedHost: undefined,
referer: 'https://members.lesbenjamins.com/';
}
{
host: '[::1]:44943',
forwardedHost: undefined,
referer: 'https://members.lesbenjamins.com/';
}
idk why it's using the local's host, but just gonna strip referer for now, and hopefully someone else has the same issue as me..
Brody
Brodyβ€’7mo ago
X-Forwarded-Host doesnt exist btw maybe you want .hostname? or req.headers.get("Host") dont know, i haven't done anything with next, i do know that this isnt an issue with railway, since as you can see from my utilities app the host header is indeed there
kevin
kevinβ€’7mo ago
gotcha, yea i think i'll just print out the entire headers, and try "Host"
Brody
Brodyβ€’7mo ago
or maybe req.host / req.hostname just try stuff lol
kevin
kevinβ€’7mo ago
nextjs is typed pretty well, so there's like not infinite options, but hopefully smth works🀞
No description
Brody
Brodyβ€’7mo ago
haha forgot about the types
kevin
kevinβ€’7mo ago
types are great πŸ™‚ i remember when i was just writing plain javascript a few years ago, can't imagine going back to that now, stuff would break all the time lol
Brody
Brodyβ€’7mo ago
i still only write js lol
kevin
kevinβ€’7mo ago
My headers unfortunately, really don't know why host is not passing πŸ€·β€β™‚οΈ perhaps related to nextjs server? hopefully someone else runs into the issue too i guess 🀞
No description
Brody
Brodyβ€’7mo ago
something to do with next for sure nextUrl ?
kevin
kevinβ€’7mo ago
just did a bit more testing but not sure, nextjs's "raw headers" look similar (host is local), and nextjs middleware is also giving me the wrong host too (local). referer is perfectly fine though, dunno why. luckily referer contains all the information i need anyways, so it's good enough for an app hotfix, hopefully on a different nextjs version, things do work, trying tmrw 🀞
Brody
Brodyβ€’7mo ago
looking forward to an update!
exclusived
exclusivedβ€’6mo ago
hi. i have the same problem. should i use referer or a solution has been found?
Brody
Brodyβ€’6mo ago
as I've mentioned previously, and demonstrated, there's nothing wrong with the host header