1

I would like to detect events from a URL address in my web application. I implemented it with Spring (backend) and Angular (frontend).

I use JWT to sign in.

In one of the components, I want to check if a POST method was sent by some user (to check if a notification was added to a database via POST mapping) for example http://localhost:8080/notifications.

So, in another component: TaskComponent I created EventSource object, on the basis of: https://github.com/Yaffle/EventSource/ in this way:

ngOnInit() {
    const eventSource = new EventSource(http://localhost:8080/notifications', {
    Authorization: 'Bearer ' + sessionStorage.getItem('AuthToken')
    });
    console.log(eventSource);
    console.log(sessionStorage.getItem('AuthToken'));
}

Login and sessionStorage.getItem('AuthToken') work fine, but after the opening http://localhost:4200/task I get 406 code, even though I'm logged in the app, which is related with notifications REST API.

bsheps
  • 1,438
  • 1
  • 15
  • 26
plkpiotr
  • 345
  • 2
  • 9
  • 23

0 Answers0