0
我们有一个非常简单的node.js/4.0表示应用程序,目前只包含一个缺省路由Node.js的简单res.render超时
/* GET home page */
router.get('/', function(req, res) {
var products = heelsProducts;
res.products = products;
res.render('index', {title: 'Shop SKINNYprice!', req: req, products: res.products, _csrf: req.csrfToken()});
});
这条线路运行正常,当我们在访问我们的本地开发机器(Fedora 19)和发布像$ curl http://localhost:3000
这样的快速测试会导致索引页html立即返回。
然而,当我们部署该代码库为我们AWS EC2实例(默认的Linux AMI)并返回该错误之前发出相同的卷曲的过程将挂起约60秒:
Error: Can't set headers after they are sent. at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:335:11) at ServerResponse.header (/root/git/skinnypriceshop/code/shop/node_modules/express/lib/response.js:662:10) at ServerResponse.send (/root/git/skinnypriceshop/code/shop/node_modules/express/lib/response.js:146:12) at fn (/root/git/skinnypriceshop/code/shop/node_modules/express/lib/response.js:896:10) at /root/git/skinnypriceshop/code/shop/node_modules/ejs-locals/index.js:134:7 at Object.exports.renderFile (/root/git/skinnypriceshop/code/shop/node_modules/ejs-locals/node_modules/ejs/lib/ejs.js:318:3) at module.exports (/root/git/skinnypriceshop/code/shop/node_modules/ejs-locals/index.js:85:7) at /root/git/skinnypriceshop/code/shop/node_modules/ejs-locals/index.js:131:7 at Object.exports.renderFile (/root/git/skinnypriceshop/code/shop/node_modules/ejs-locals/node_modules/ejs/lib/ejs.js:318:3) at View.module.exports [as engine] (/root/git/skinnypriceshop/code/shop/node_modules/ejs-locals/index.js:85:7)
一些网上搜索对于这个问题似乎表明,某种后续响应正在尝试写入头文件,但是我们在代码中看到的任何东西似乎都不适用于此。
任何想法在这一点上,将不胜感激。
您是否在使用会影响该路线的任何自定义中间件? – 2015-02-09 00:46:53
我认为问题在于'res.render'调用中使用'res'对象只是说'产品'并删除'res.products = products'行。 – Mritunjay 2015-02-09 03:09:31
yzarubin - 用上面的评论回答问题,我会将其标记为已接受。最后,您确定存在介入服务器上未启动的中间件(memcached)。另外Mritunjay你是正确的关于res.products =产品是外挂。是不是问题的根源,但没有帮助:) – Gatmando 2015-02-09 15:11:31