Hi!
I am building a next app which redirects the user from the middleware after making some changes to the nexturl. Unfortunately the redirected link is a localhost url, while it should have the hostname given by render.
To specify the hostname to the nextjs app, I used the RENDER_EXTERNAL_URL env variable and passed it to the start cmd for hostname argument
pnpm start --hostname $RENDER_EXTERNAL_URL
This gives the following error
⨯ Failed to start server
Error: getaddrinfo ENOTFOUND https://onthemenu-preview-pr-24.onrender.com
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'https://onthemenu-preview-pr-24.onrender.com'
}
Looks like your service is trying to resolve https://onthemenu-preview-pr-24.onrender.com which isn’t a host; it’s a URL. What happens if you use RENDER_EXTERNAL_HOSTNAME instead.
Note, I’m not sure I understand your mentioning of localhost. I don’t see where this is involved, with the information you have provided.
I tried the solution, but still got the same error.
’’’
==> Running ‘pnpm run start --hostname $RENDER_EXTERNAL_HOSTNAME’
onthemenu-v1@0.1.0 start /opt/render/project/src
next start “–hostname” “onthemenu-v1.onrender.com”
⨯ Failed to start server
Error: listen EADDRNOTAVAIL: address not available 216.24.57.4:10000
at Server.setupListenHandle [as _listen2] (node:net:1880:21)
at listenInCluster (node:net:1945:12)
at GetAddrInfoReqWrap.doListen [as callback] (node:net:2109:7)
’’’
Ah, --hostname on next start defines what host the server will bind to. You don’t want to change this as its default is 0.0.0.0 and this is a requirement for a Render web/private service: https://docs.render.com/web-services#port-binding.
If you still have issues after removing this, please open a ticket directly with us so we can have a closer look at the specific service having issues.