angular-sails
angular-sails copied to clipboard
New feature: could you add option to set default headers?
angularSails supports setting of default headers, could angular-sails also support that? Check http://balderdashy.github.io/angularSails/#/api/ngsails.$sailsSocket, under Setting Headers. By the way, awesome library, has nice documentation and everything, I like it much more than angularSails. Thanks!
We are trying to update everything to work with the new sails.io.js abilities while still working for older sails.io.js. Headers is one of the things that is involved with this. Its in the works along with full test suites for more code confidence as its a lot of changes.
See; https://github.com/janpantel/angular-sails/blob/master/src/service/angular-sails.js#L67 You could add a request interceptor which adds your headers.
That will not work because angular-sails uses sails.io.js. sails.io.js will just ignore the headers when it makes the actual call. See: https://github.com/balderdashy/sails.io.js/blob/master/sails.io.js#L725
Is token based Authentication currently possible with angular-sails.., it needs the authorization header?
headers (and thus setting the auth header) is on the roadmap for 2.0 which is not 100% ready(the build is passing and what is there works, but not feature complete), but close.
Oh rlly? No header support?
Looked into my sails project: Ive a /login
and /login/authSocket
route with support to authenticate the Socket. So i dont have to send credentials every request.
Any update on the progress on this? As I also would like to be able to send a token in the header.
+1
+1
I was going to mention beta release of 2.0 and say that it has default headers... but it has been a while since I made it and looking at it now I see.... // TODO: default headers
:(
But while I'm at it... RFC for what the default default headers should be (if any). Angular's $http
has some defaults mostly around Content-Type
... not sure if that is relevant with $sails
or not.
So... there is now 2.0 beta 2 release. It has default headers abilities similar to how angular's $http
works, just use $sailsProvider
instead of $httpProvider
(i.e. $sailsProvider.defaults.headers.get = {'my-header': 'some value'}
).
Let me know if you have any issues with 2.0 beta.
I have just tested this with the following from an AuthService:
$sails.defaults.headers.common = {'Authorization' : 'Bearer ' + token}; $sails.defaults.headers.post = {'Authorization' : 'Bearer ' + token};
Checking the socket frames in chrome devtools I can see that the headers appear to be empty.
Is it possible to automatically append the http headers to the socket, which means we just have to replace the $http with $sails?
@snowcxt not sure what you mean. Something like "use the headers set in $httpProvider.default.headers
when making $sails
calls? So it would be something like
finalHeadersSent
<- $http.default.headers.common
<- $http.default.headers[method]
<- $sails.default.headers.common
<- $sails.default.headers[method]
<- request.config.headers
Each one extending the other to add or override the values.
That could be useful when you want to use both $http
and $sails
together so you don't have to duplicate setting the headers on $httpProvider
and $sailsProvider
Although you could just do $sailsProvider.default.headers = $httpProvider.default.headers
to make them the same thing.
Right. And it's nice to have the "headers" parameter in the $sails function as what $http does.
It is. You can pass headers in the config and they will be merged into the defaults. Current it is set up to do something like:
finalHeadersSent
<- $sails.default.headers.common
<- $sails.default.headers[method]
<- request.config.headers
@AdamJessop It turns out that if I don't actually update the dist files, then no one gets them :( lol.. yeah, I forgot to run gulp to create the dist files that you use. So 2.0.0-beta-2 dist files are actually 1.x... No fear, 2.0.0-beta.3 has the legit dist files now and you should be able to see the headers working! Give it a try.
@snowcxt as far as your request. I would probably put that ability behind a flag, and if I were to do that and have users/devs set the flag, I might as well just recommend doing $sailsProvider.default.headers = $httpProvider.default.headers
as it would be the same affect.
Has this feature been implemented yet ? Doesn't look like it has, but I may be wrong ...
Any update on this?