Hello,
i’m trying to set a sync gateway web-hook in Nodejs.
Previously i used iriscouch/follow https://github.com/iriscouch/follow package, but i saw that after updating SG to 2.1 community edition, the feed doesn’t work anymore, and every time i save a document, the onFeed
callback is not called…
The sync_gateway.json:
{
"CORS": {
"Origin":["*"],
"Headers": ["Content-Type"]
},
"admin_interface": ":4985",
"interface":":4984",
"databases": {
"omnitrace_cluster": {
"bucket": "omnitrace",
"password": "123123",
"username": "Administrator",
"server":"http://127.0.0.1:8091",
"enable_shared_bucket_access": true,
"use_views": true,
"users": {
"GUEST": {"disabled": false, "admin_channels": ["*"]}
},
"sync": `function (doc, oldDoc) {
channel(doc.channels);
}`
}
}
}
The feed bootstrap file
/*
* Registering the sync gateway listener
*
*/
const config = require('../config/database')
const host = config.couchbase.host
const protocol = config.couchbase.protocol
const clusterName = config.couchbase.cluster
const port = config.couchbase.sync_gateway_port
const follow = require('follow')
const opts = {
db: `${protocol}://${host}:${port}/${clusterName}`,
include_docs: true,
since: 'now'
}
const feed = new follow.Feed(opts)
feed.on('change', async (change) => {
console.log('ok')
//some stuff
})
feed.on('error', async (error) => {
console.log('Error in couchbase provider sync follow')
console.log(error)
})
feed.follow()
I saw in the documentation that the right approach is to use either change feed
or web-hooks
https://docs.couchbase.com/sync-gateway/2.1/server-integration.html.
I was wondering if someone could explain me better the workflow, because the docs are a bit confusing.
In particular, i didn’t understand if the web-socket connection should be made by the server(like iriscouch/follow) or in the client.
Also, for better performance it is recommend to implement change feed
hooks rather than webhooks
, right?
Thanks in advance