SAFE-Stack / SAFE-template

dotnet CLI template for SAFE project
MIT License
280 stars 87 forks source link

devServerProxy not working (ECONNREFUSED) #518

Closed 0101 closed 1 year ago

0101 commented 2 years ago

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 :)

olivercoad commented 2 years ago

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