The problem is here:

getBusinesses(response) {
    ref.orderByKey()
    .limitToLast(20)
    .on('value', function(snapshot){
        response.json(snapshot.val()); 
        return snapshot.val();
    })
}

Since you’re using on(...), your callback will be called:

  1. As soon as the data is loaded,
  2. After that, any time the data changes.

The first one is working as intended, but if the data ever changes this means you’re trying to send another response, which is what’s causing the error.

To solve this, use once instead of on:

getBusinesses(response) {
    ref.orderByKey()
    .limitToLast(20)
    .once('value', function(snapshot){
        response.json(snapshot.val()); 
        return snapshot.val();
    })
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top