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 <[email protected]> wrote: > 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 >
