Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova adding port to external links on cordova run browser

I'm building a test chat app client with node.js, socket.io and cordova. Executing cordova run browser browser opens to http://localhost:8000. In index.js of my cordova chat client app i got code to connect to my server side socket.io:

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

Problem is that i receive this kind of error:

enter image description here

So as you can see there is a port (8000) added to the link. This problem is not occuring when I run app on android device (cordova run android).

Why cordova is adding port to external links ? Can disable port adding to external links on cordova run browser ?

like image 507
born2fr4g Avatar asked Oct 19 '22 15:10

born2fr4g


1 Answers

It's not cordova adding port to your URL, it's socket.io client, here:

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

When port is not defined, it defaults to port of application. That is probably a bug in socket.io, since it makes sense only if webpage and server are hosted from same node. Your problem originates from the fact, that it is cordova which serves your application (on localhost:8000) and socket.io assumes that websocket will be on same port.

To avoid it, you should add port to URL or the options object.

like image 199
Koder Avatar answered Oct 21 '22 12:10

Koder