SAFE-template icon indicating copy to clipboard operation
SAFE-template copied to clipboard

devServerProxy not working (ECONNREFUSED)

Open 0101 opened this issue 3 years ago • 1 comments

After creating a new project from the template (v3.1.1) and starting it up, communication between client and server doesn't work. In the console I see:

client: [HPM] Error occurred while trying to proxy request /api/ITodosApi/getTodos from 0.0.0.0:8080 to http://localhost:8085 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)

I don't know if this is caused by some mis-configuration of my system (MacOs Big Sur) but it could probably affect others as well.

After a while I managed to fix it by changing the devServerProxy to target 0.0.0.0 instead of localhost:

devServerProxy: {
  // redirect requests that start with /api/ to the server on port 8085
  '/api/**': {
      target: 'http://0.0.0.0:' + (process.env.SERVER_PROXY_PORT || "8085"),
         changeOrigin: true
     },
  // redirect websocket requests that start with /socket/ to the server on the port 8085
  '/socket/**': {
      target: 'http://0.0.0.0:' + (process.env.SERVER_PROXY_PORT || "8085"),
      ws: true
     }
 }

Not sure if this change could have some adverse effects on someone else's system. So hopefully someone who understands this better than me can pitch in :)

0101 avatar Jun 02 '22 17:06 0101

If you're using node version 17 or higher, see #490.

olivercoad avatar Jun 03 '22 07:06 olivercoad