onch-at/onchat-web

Proxy connection refused

Opened this issue · 1 comments

Hello! I am interested in your project and wanted it to run on my machine.

I get the following error after I have run ng build and then ng serve:
[HPM] Rewriting path from "/ws/socket.io/?EIO=3&transport=websocket" to "/socket.io/?EIO=3&transport=websocket" [HPM] GET /ws/socket.io/?EIO=3&transport=websocket ~> http://localhost:9501 [HPM] Upgrading to WebSocket [HPM] Error occurred while trying to proxy request /socket.io/?EIO=3&transport=websocket from localhost:4200 to http://localhost:9501 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)

Can you help me with this? I have not done any project in angular before and I do not know where to start investigating this error. Do I need to set up a localhost at 9501 as well?

This project is still in the development and testing stage, but a temporary solution can be provided:

This project does need a back-end server as the API provider. Since the project is still in the development and testing stage, you can temporarily use the remote back-end server provided by me. You will not need to build the back-end server yourself.

The following is the configuration method:

  1. Use tool mkcert to generate development certificates for the localhost domain name. This will result in a cert file and a key file.
  2. Rename the cert file to localhost.pem
  3. Rename the key file to localhost-key.pem
  4. Move these two files to the project root directory
  5. Open the project root directory
  6. Open the proxy.config.json file and replace all the original configuration of the file with the following configuration:
{
     "/onchat": {
         "target": "https://api.chat.hypergo.net",
         "secure": "false",
         "logLevel": "debug",
         "changeOrigin": true,
         "pathRewrite": {
             "^/onchat": ""
         }
     }
}
  1. Open the src/environments/environment.ts file, find socketUrl, and modify its value to https://api.chat.hypergo.net, example:
export const environment = {
   // Omit part of the code
   socketUrl:'https://api.chat.hypergo.net',
   // Omit part of the code
};
  1. Save all files, open the command line, and execute the command npm run https
  2. Visit https://localhost:4200 in the browser

Related information

Back-end code repository: OnChat
Front-end code repository: OnChat-Web

If you like this project, welcome to star these two code repositories! ⭐