js-algorand-sdk icon indicating copy to clipboard operation
js-algorand-sdk copied to clipboard

algosdk.Algodv2 overwrites empty port parameter

Open tholcman opened this issue 3 years ago • 4 comments

Subject of the issue

const client = new algosdk.Algodv2("DUMMYTOKEN", "http://127.0.0.1:17458");

Should create a client which will request port 17458, but the client requests port 4180.

it is overwritten here:

https://github.com/algorand/js-algorand-sdk/blob/develop/src/client/v2/algod/algod.ts#L27

Your environment

SDK version 1.12.0, develop branch, ...

Steps to reproduce

  1. Use an URL with defined non-standard port without port parameter
  2. ...

Expected behaviour

It should request a algod on "http://127.0.0.1:17458"

Actual behaviour

it requests "http://127.0.0.1:4180"

tholcman avatar Oct 18 '21 13:10 tholcman

If you set the URL to the base URL and pass the port as the third argument it should work.

barnjamin avatar Oct 18 '21 13:10 barnjamin

I know, I have figured it out, I have also figured out where the bug is. And it IS a bug. Or do you think that it is right, that it is secretly overwriting generally accepted standard URL?

We are passing it from "outside", and depends on where our app is running, it may have different forms. So we would need to parse it before instantiating the algod client, set the third argument, then it is passed through several constructors, parsed again and the port will be put back it feels really wrong.

And it is also very confusing that something standard doesn't work.

tholcman avatar Oct 18 '21 17:10 tholcman

@tholcman yes I agree the behavior is a bit odd. If you pass an empty string "" for the port though, I believe it will not get overridden and will work as intended.

We should improve our documentation on this.

jasonpaulos avatar Oct 18 '21 18:10 jasonpaulos

:) empty string also tested by a colleague ... and it is even better ... it ended on port :80

but I am not 100% sure about that

tholcman avatar Oct 18 '21 18:10 tholcman

Closing in favor of #657

winder avatar Sep 23 '22 15:09 winder