3

I'm trying to proxy a request to a backend with Next rewrites.

next.config.js:

async rewrites() {
  return [
    {
      source: "/api/:path*",
      destination: "http://somedomain.loc/api/:path*",
    },  
  ]
},

/etc/host:

127.0.0.1  somedomain.loc

and in the end i get this error:

Failed to proxy http://somedomain.loc/api/offers Error: connect ECONNREFUSED 127.0.0.1:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 80
}
error - Error: connect ECONNREFUSED 127.0.0.1:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 80
}

While if you make a request via postman or directly from the browser, everything works fine.

Please help me understand what is the problem here.

tried: Proxy request to backend expected: The request is proxied to the backend as a result: Proxy error

Vladyslav
  • 51
  • 4
  • I'm facing the same issue. Were you able to find a solution to this? – Manish Singh Jan 11 '23 at 20:08
  • 2
    Alright, using the IP address `127.0.0.1` instead of the domain name `localhost` worked for me. The issue might be with the domain name resolution with NextJS. – Manish Singh Jan 11 '23 at 20:14
  • I am using the IP address and not localhost... If I type the URL directly into the browser it works, but not when I have the request rewritten by Next.js – Zargold Feb 13 '23 at 17:55

0 Answers0