The SSE(subscribe a event in Browser) seems not support CORS?

Hi @Dave,

I known you are expert for spark local server. :slight_smile:

After lots of try and testing , i found that the Local server do not support sse with cors in browser ?

below is my code, which got nothing error, the connection will keep connected, but nothing got in browser , after debugging the server found : it will return ‘/n’ from server continued without error.

var evtSource = new EventSource("");

evtSource.onmessage = function(e) {
	  alert("EventSource failed.");

      $( "#container3" ).append( "<strong> YES, we now receive the event from serve side ! "  + "</strong> !" );

evtSource.onerror = function(e) {
	  alert("EventSource failed.");

Heya @yuanetking,

Hmm… There are a few questions here, SSE, CORS, and events in general, so assuming that the following works:

  • You can open that url directly, and see events in that browser window?

I think the latest Spark server package allows cross origin requests from everybody, code is here:

So I’m guessing the issue is more about specifying the specific event name when binding your eventSource object. Checkout this post for an example of how to bind to a specific eventsource topic:

I hope that helps! :slight_smile:


1 Like

Hi @Dave ,

The code of emc2 are using the sse simulator in nodejs which is different with my way which i am calling the cloud server on the browser side directlly.

I just test the way from emc2 it works fine . and maybe the better choice for me . :smile:

Thx @Dave & @emc2

1 Like

Hi ,@Dave,

I found , below url will work:***************************

But below url wont work, my event named “my-event” comes from Spark Core.***************************************************


Hi @yuanetking,

Ahh, thanks for clarifying! I think this makes sense, and might be related to some features I’d like to add to the local cloud the next chance I get. :slight_smile: