Use EventSource to Listen event from openHAB

I try to listen a changing of items from openHAB with EventSource by a client i coded by VueJS. But no message can be receive from openHAB and i got data of var es = new EventSource('http://localhost:8080/rest/events/state) is
EventSource {url: “http://localhost:8080/rest/events/states”, withCredentials: false, readyState: 0, onopen: null, onmessage: null, … in console. Anyone have a solution for this. Thanks all !!!

  1. you need session cookie first
  2. then you receive uuid
  3. finally you POST list of items to /rest/states/$uuid
  4. you start receiving events

Best,
Łukasz

when i session cookie, i got CORS error. This error is Cross-Origin Resource Sharing error InvalidAllowCredentials but i had written like this in ES setup section:

let es = new EventSource(
	"http://localhost:8080/rest/events/states",
	{
		withCredentials: true,
		header:{
			'Access-Control-Allow-Credentials': true,
			"Access-Control-Allow-Origin": "http://localhost:8081"
		}
					
	}
);

port 8081 is my client port

Apparently OH does not return valid CORS headers for your client. Given that you use distinct ports web browser will complain.

Have a look on this: Cors problem - #2 by Fab4guy. There were some fixes also for authorization headers, however in your case it should not apply (since you rely on cookie which is set per domain name).

Best,
Łukasz

how can i find file runtime.cfg when i install openHAB on Docker ?