Closed ioana-m closed 7 years ago
Hello, I was able to resolve my issue, by using the instance of ngstompProvider returned when url was set in config in the module run function. Very easy, son't know why I did't see it before. Thank you for the nice plugin.
I really like when issue are closed so fast 😄
Could you provide a code example of the solution, if someone want to do it ?
Sure here is what worked for me.
var stompProvider = null;
config.$inject = ['ngstompProvider'];
function config(ngstompProvider) {
stompProvider = ngstompProvider.url('/ws').class(SockJS).debug(true).autoConnect(false);
}
run.$inject = ['ngstomp', '$cookies'];
function run(ngstomp, $cookies) {
stompProvider.headers({
'X-XSRF-TOKEN': $cookies.get("XSRF-TOKEN")
});
ngstomp.connect();
}
What you've done is a good idea, but I think this should be done without using external variable.
You can also do this :
config.$inject = ['ngstompProvider'];
function config(ngstompProvider) {
ngstompProvider.url('/ws').class(SockJS).debug(true).autoConnect(false);
}
run.$inject = ['ngstomp', '$cookies'];
function run(ngstomp, $cookies) {
ngstomp.settings.headers({
'X-XSRF-TOKEN': $cookies.get("XSRF-TOKEN")
});
ngstomp.connect();
}
Thank you for the suggestion, but I just tried it and it says. ngstomp.settings.headers is not a function.
I should have test my code example...😢
config.$inject = ['ngstompProvider'];
function config(ngstompProvider) {
ngstompProvider.url('/ws').class(SockJS).debug(true).autoConnect(false);
}
run.$inject = ['ngstomp', '$cookies'];
function run(ngstomp, $cookies) {
ngstomp.settings.headers = {
'X-XSRF-TOKEN': $cookies.get("XSRF-TOKEN")
};
ngstomp.connect();
}
It should be better 😄
Yes, thank you, it works.
Could you please help. I am trying to add the X-XSRF-TOKEN token to headers. I get the token using $cookies service from angular, so I don't have access to it in module config only in run, and I cannot seem to find a way of changing the headers used on connect to stomp in module run.
This is what I wrote in module config: ngstompProvider.url('/ws').class(SockJS).debug(true).autoConnect(false);
How can I then set the header in module run, for this to work with spring CSRF websocket security: ngstomp.connect();
Thank you.