custom domain getting redirected to port :8080
sonipranjal
PROOP

3 months ago

i deployed the website to vibedream.ai when i go to the website

it automatically concat :8080 and doesn't work

urgent help needed

Solved$20 Bounty

Pinned Solution

domehane
FREETop 10% Contributor

3 months ago

the issue is that railway's reverse proxy exposes the internal port to Next.js, and when you use .host it includes the port. Using .hostname and explicitly clearing .port fixes it

see this example if you need to fix the Middleware properly when building redirect URLs in Next.js middleware, use:

this is wrong it includ port :

const url = request.nextUrl.clone()

url.host = 'www.vibedream.ai'

the correct way is no port in production :

const url = request.nextUrl.clone()

url.hostname = 'www.vibedream.ai'

url.port = ''

this removes the port from the URL

6 Replies

3 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open brody 3 months ago


domehane
FREETop 10% Contributor

3 months ago

does the :8080 also appear when you visit your Railway-provided .up.railway.app domain, or only on vibedream.ai?


sonipranjal
PROOP

3 months ago

there was a middleware that was pushed by my dev, i removed it and now it seems to be working, but only in incognito mode, in existing tabs it doesn't work, might have to reset the cache or something
middleware job was to redirect non www to www
seems like some issue internally how reverse proxy and nextjs middleware works


domehane
FREETop 10% Contributor

3 months ago

the issue was your next.js middleware that redirects non-www to www was incorrectly including :8080 in the redirect url

it works in incognito but not regulat tabs beacaus the browser cached the bad redirect http 301/302 with :8080 in it

so you should hard refresh the browser cache for Chrome/Edge: Ctrl+Shift+R (Windows) or Cmd+Shift+R (Mac) ;; for Firefox: Ctrl+F5 or Cmd+Shift+R

or clear browsing data for vibedream.ai


domehane
FREETop 10% Contributor

3 months ago

the issue is that railway's reverse proxy exposes the internal port to Next.js, and when you use .host it includes the port. Using .hostname and explicitly clearing .port fixes it

see this example if you need to fix the Middleware properly when building redirect URLs in Next.js middleware, use:

this is wrong it includ port :

const url = request.nextUrl.clone()

url.host = 'www.vibedream.ai'

the correct way is no port in production :

const url = request.nextUrl.clone()

url.hostname = 'www.vibedream.ai'

url.port = ''

this removes the port from the URL


domehane
FREETop 10% Contributor

3 months ago

your site should work fine now


sonipranjal
PROOP

3 months ago

yes this was the issue

thanks
told my dev to fix it


Status changed to Solved brody 3 months ago


Loading...