快速请求被两次调用 [英] Express request is called twice
问题描述
要学习node.js,我正在创建一个小型应用程序,该应用程序将一些rss提要存储在mongoDB中,对其进行处理,并从中创建一个单独的提要(按日期排序).
To learn node.js I'm creating a small app that get some rss feeds stored in mongoDB, process them and create a single feed (ordered by date) from these ones.
它解析约50个rss提要的列表,其中包含约1000个博客项目,因此要解析整个提要很长,因此我放置了以下req.connection.setTimeout(60*1000);
来获得足够长的时间来获取和解析所有提要
It parses a list of ~50 rss feeds, with ~1000 blog items, so it's quite long to parse the whole, so I put the following req.connection.setTimeout(60*1000);
to get a long enough time out to fetch and parse all the feeds.
一切正常,但是请求被调用两次. (我与Wireshark进行了核对,我认为这与Favicon无关).
Everything runs quite fine, but the request is called twice. (I checked with wireshark, I don't think it's about favicon here).
我真的不明白.
您可以在这里进行自我测试: http://mighty-springs-9162. herokuapp.com/feed/mde/20 (它应该使用有关"mde"的最后20篇文章创建一个rss feed.)
You can test yourself here : http://mighty-springs-9162.herokuapp.com/feed/mde/20 (it should create a rss feed with the last 20 articles about "mde").
代码在这里: https://github.com/xseignard/rss-unify
如果我们关注有趣的地方:
And if we focus on the interesting bits :
我有一条这样定义的路线:app.get('/feed/:name/:size?', topics.getFeed);
I have a route defined like this : app.get('/feed/:name/:size?', topics.getFeed);
topics.getFeed
是这样的:
function getFeed(req, res) {
// 1 minute timeout to get enough time for the request to be processed
req.connection.setTimeout(60*1000);
var name = req.params.name;
var callback = function(err, topic) {
// if the topic has been found
if (topic) {
// aggregate the corresponding feeds
rssAggregator.aggregate(topic, function(err, rssFeed) {
if (err) {
res.status(500).send({error: 'Error while creating feed'});
}
else {
res.send(rssFeed);
}
},
req);
}
else {
res.status(404).send({error: 'Topic not found'});
}};
// look for the topic in the db
findTopicByName(name, callback);
}
所以没什么花哨的,但仍然,此getFeed函数被调用了两次.
So nothing fancy, but still, this getFeed function is called twice.
那是怎么了?有什么主意吗?
What's wrong there? Any idea?
推荐答案
这使我很烦了.很可能是Firebug扩展,它在后台发送每个GET请求的副本.尝试关闭Firebug,以确保不是问题所在.
This annoyed me for a long time. It's most likely the Firebug extension which is sending a duplicate of each GET request in the background. Try turning off Firebug to make sure that's not the issue.
这篇关于快速请求被两次调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!