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