Getting EventSource changes feed working

471 views
Skip to first unread message

Peter Figliozzi

unread,
Feb 11, 2016, 1:10:42 PM2/11/16
to us...@couchdb.apache.org
I am trying to get the changes feed working using the Event Source method.
Here is the example from the docs
<http://docs.couchdb.org/en/1.6.1/api/database/changes.html>:

// define the event handling function
> if (window.EventSource) {
> var source = new EventSource("/somedatabase/_changes?feed=eventsource");
>
> var results = [];
> var sourceListener = function(e) {
> var data = JSON.parse(e.data);
> results.push(data);
> };
> // start listening for events
> source.addEventListener('message', sourceListener, false);
> // stop listening for events
> source.removeEventListener('message', sourceListener, false);
> }


When I work up something similar, I get the following error message:

EventSource's response has a MIME type ("text/plain") that is not
"text/event-stream". Aborting the connection.

*So I believe I need to tell the changes feed to use "text/event-stream"
instead of "text/plain". How is that done?*

In this case I am working from the browser, passing the url in the
EventSource constructor:

var source = new EventSource("/somedatabase/_changes?feed=eventsource");

Thank you,

Pete

Peter Figliozzi

unread,
Feb 11, 2016, 3:42:01 PM2/11/16
to us...@couchdb.apache.org
My bad, I had formed my URL incorrectly, like this:

"/somedatabase/_changes/feed=eventsource"

Note the '/' instead of a '?'.

Apparently this caused it to use the 'normal' changes feed, with
response type 'text/plain'.

The 'eventsource' feed works just fine, out of the box.

Pete


On Thu, Feb 11, 2016 at 12:10 PM, Peter Figliozzi <pete.fi...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages