我收到了这个错误。
- Error: Can't set headers after they are sent.
- FIREBASE WARNING: Exception was thrown by user callback. TypeError: req.next is not a function
我运行topsearch.html并且它正常运行。但是,当我使用搜索查询另一个页面时,它显示错误如上所述
以下是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});
}
}