Title: Cordova adding port to external links on cordova run browser
Tags: javascript;node.js;cordova;socket.io;localhost
Question: 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:



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 ?

Comment: Actually I remove it completely because it was causing another errors (refuse to connect to resorce) but its not the case ;). Why there is a port added to link placed in Javascript - with added port to the end of the url addess is just not correct

Comment: @stdob-- yes Im aware of that - but I would have to know what port is using by my heroku test server (its not 443 because there is connection timeout erron in chrome dev console)

Comment: @robert  what config do you mean ? I just run : cordova run browser and this will open up browser with adress localhost:8000. In my server app (which is running constantry) I got:
http.listen(process.env.PORT || 8000, function(){
    console.log('listening on *:8000');
})

Comment: Did you configure CSP (Content-Security-Policy) correctly in your index.html?

Comment: What does your config look like? e.g. app.set('port', process.env.PORT || 8000); process.env.PORT is set by the environment you run your code.

Comment: You can simple add default https port: `var socket = io.connect('https://node-socket.io-address:433/');` (or another port if different)

Here is the accepted answer: It's not cordova adding port to your URL, it's socket.io client, here:

```  this.port = opts.port || (global.location &amp;&amp; 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 ```opt```ions object.

Comment for this answer: That's what I thought at first - to add port to link but I dont know what port is used by my socket.io backend application hosted on Heroku - I tried :443 (since my Heroku url was on https) but it didnt work ;). Is there any solution (maybe online solution) to check port having only URL ?
Comment for this answer: Hmm i don't know how to use it - but I will check it out. Got any tips for that ? Anyway thank you for your answer - bounty is yours ;)
Comment for this answer: You should use Heroku's HTTP routing feature to do that.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 6, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:02/10/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><node.js><cordova><socket.io><localhost>', 'Title': 'Cordova adding port to external links on cordova run browser', 'ViewCount': 806, 'id': 35314142, 'user_AboutMe': '', 'user_AccountId': 893181.0, 'user_DisplayName': 'born2fr4g', 'user_Reputation': 1288.0, 'user_Views': 112.0, 'user_id': 931067.0}}