skip to Main Content

I have successfully deployed React app on digitalocean droplet with mongodb.

My server configured with nodejs nginx pm2 and everything is working fine
here is my site

www.xdomain.ml

But I build my react app to connect with the backend nodejs api.
I am using socket.io and axios to connect.

everything is working fine on my local computer but it could not connect on the server.

my socket configuration is like

const socket = io("localhost:5000")

and axios is like

axios.post("http://localhost:5000/delete-domains")

on browser console, showing

polling-xhr.js:198 GET https://localhost:5000/socket.io/?EIO=4&transport=polling&t=NjNh9TP net::ERR_SSL_PROTOCOL_ERROR

what I am missing?

do I need to replace the localhost:5000 to 127.0.0.1:5000 on code and build again?

But the mongodb connection successfully establish by

"mongodb://localhost:27017/api";

please help
Thanks

2

Answers


  1. Try to change

    const socket = io("localhost:5000")

    to

    const socket = io("http://localhost:5000")

    Or other advance setting:

    const socket = io.connect('http://localhost', {
        port: 5000,
        reconnect: true
    });
    
    Login or Signup to reply.
  2. const socket = io("localhost:5000")

    on this line you are missing "http://" or if you have ssl "https://"
    this line should be

    const socket = io("http://localhost:5000");

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search