NextJS rewrites error while proxying a request to the backend

2.3k views Asked by At

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

0

There are 0 answers