我一直在运行 Node 0.8.25 和 Express 3.4.0。
效果很好。
我尝试升级到 Node 0.10 Stable,但我开始遇到奇怪的问题。
例如,我有一条看起来(有点)像这样的路线:
app.post( "/toPDF", auth.isAuthorized, function( req, res, next ){
getPDF( req.data, function( err, pdfData ) {
if ( err ) {
next( err );
} else {
res.setHeader( "Content-type", "application/pdf" );
res.setHeader( "Cache-Control", "no-cache" );
res.setHeader( "Accept-Ranges", "none" );
res.setHeader( "Content-Disposition", "inline; filename=stuff.pdf" );
res.end( pdfData.raw, "binary" );
}
});
});
升级到 Node 0.10 后,我第一次调用这条路由时,一切正常。
然而,第二次调用该路由时,应用程序崩溃并显示“ header 已发送”错误。
我想看看响应中已经存在哪些 header 。因此,在发送任何 header 之前,我将以下内容添加到 getPDF 回调的顶部。
console.log( res._headers );
就在它崩溃之前,输出:
Content-type application/pdf
Cache-Control no-cache
Accept-Ranges none
Content-Disposition inline; filname = stuff.pdf
看起来好像我的旧响应对象以某种方式徘徊?知道这里会发生什么吗?
最佳答案
您可能在中间件的某处调用了 next() 两次 - 检查 auth.isAuthorized 或您正在使用的任何其他。如 this question 中所述.
关于javascript - 升级到 Node 0.10 后的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18945112/