Cordoba adds port for external links to cordova browser browser

I am creating a test chat application client with node.js, socket.io and cordova. Running the cordova run browser browser opens http: // localhost: 8000 . In the index.js of my chatova chat chat application, I got code to connect to the server side of socket.io:

 var socket = io.connect('https://node-socket.io-address/'); socket.on('connect', function() {............. 

The problem is that I get this error:

enter image description here

So, you can see that the port (8000) has been added to the link. This problem does not occur when I run the application on an Android device (android rootova).

Why does cordova add port to external links? Can disable port add to external links on roova browser browser ?

+5
source share
1 answer

This is not a Cordova adding a port to your URL, it is a socket.io client, here :

  this.port = opts.port || (global.location && location.port ? location.port : (this.secure ? 443 : 80)); 

If no port is specified, the default port is the application port. This is probably an error in socket.io, as it only makes sense if the web page and server are hosted from the same node. Your problem arises because it is a cord that serves your application (on localhost: 8000) and socket.io assumes that websocket will be on the same port.

To avoid this, you should add a port to the URL or opt ion object.

+3
source

Source: https://habr.com/ru/post/1242700/


All Articles