Saturday, 13 May 2017

Error: Can't set headers after they are sent. and TypeError: req.next is not a function

I got this error.

- Error: Can't set headers after they are sent. 
- FIREBASE WARNING: Exception was thrown by user callback. TypeError: req.next is not a function 
- TypeError: req.next is not a function

I run topsearch.html and it working properly. But when I use search to query another page It's show error as above

Here is code on app.js

    var express = require('express')
    var app = express()
    app.engine('html', require('ejs').renderFile)
    app.use(express.static('public'))
    app.get('/topsearch',showTopsearch)

function showTopsearch(req, res){
    database = firebase.database();
    var ref = database.ref('urls');
    ref.on('value', gotData, errData);

    function errData(err){
        console.log('Error!');
        console.log(err);
    }

    function gotData(data){
        result = data.val() 
        const urls_kws = Object.keys(result)
                    .filter(key => result[key].last_res > 10)
        var top_keywords = [];

        for(var i = 0; i < urls_kws.length; i++){
            top_keywords.push(urls_kws[i]);
        }

        for(var i=0;i<top_keywords.length;i++) {
        top_keywords[i] = top_keywords[i].replace(/-/gi, " " )
        }
        res.render('topsearch.html', {top_keywords:top_keywords, urls_kws:urls_kws});
    }
}



via Moomoo Soso

No comments:

Post a Comment