Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass custom query params to socket connection #78

Open
dakairus opened this issue Jun 29, 2015 · 2 comments
Open

pass custom query params to socket connection #78

dakairus opened this issue Jun 29, 2015 · 2 comments

Comments

@dakairus
Copy link

Hi guys,I been using this lib for a while, works awesome. I'm using it in a work project. Few days ago I got a request from my client that they want to use JWT, pass it into the socket connection query to validate into their server API.

I tried to set into de $sailsProvider the config.query value, but the query params that I added(a JSON with 3 different tokens) never reach the server, after a while reading how the library works I found this:

      if(!angular.isString(config.query)){
        config.query = sailsSdk.versionString();
      }else{
        config.query += '&'+sailsSdk.versionString();
      }

config.query if is not a string is overwritten with sailsSdk.versionString(), so I made a modification:

      if(!angular.isString(config.query)){
        var tmp = [];
        angular.forEach(config.query, function(value,key){
          tmp.push(key+'='+value);
        });
        var query = tmp.join('&');
        config.query = sailsSdk.versionString() + '&' + query;
      }else{
        config.query += '&'+sailsSdk.versionString()+ '&' + config.query;
      }

So in this way if the config.query is a JSON it appends the every key and value to the query.

Hope this help you guys.

@TheSharpieOne
Copy link
Contributor

Per socket.io, the config's query must be a string, which is why it's limited to a string here. Yes, it would be nice to handle an object for the dev and turn it into a string (instead of making them do it before setting the value on config, which is the correct and intended use), but it is not as easy as that forEach. What is there are nested objects where value itself would be an object? Lucky, there is already a utility to sorta do this, but would need some adjustments to build the query string separate from the url.

@dakairus
Copy link
Author

Hi, thx for the feedback. Well, yes is a problem if a nested JSON value is present, but is just the approach that I find by the moment, will be really nice have a option to build the url using the params.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants