1

我有一个节点服务器,用作我的 iPhone 应用程序的 API 服务器。此时,当应用程序拉下一些随机文件(比如图片或视频文件)时,我会随机崩溃。

我是节点新手,我真的不明白为什么会崩溃。关于文件服务的服务器代码并不多。我只是将文件放在我的“上传”目录中。它在大多数情况下都有效,但随后会出现间歇性崩溃。

stream.js:81
      throw er; // Unhandled stream error in pipe.
            ^
Error: socket hang up
    at createHangUpError (http.js:1360:15)
    at ServerResponse.OutgoingMessage._writeRaw (http.js:507:26)
    at ServerResponse.OutgoingMessage._send (http.js:476:15)
    at ServerResponse.OutgoingMessage.write (http.js:749:16)
    at ServerResponse.module.exports.res.write (/Users/sigma/Development/Node.js/sigma-app/node_modules/express/node_modules/connect/lib/middleware/compress.js:82:17)
    at ondata (stream.js:38:26)
    at EventEmitter.emit (events.js:96:17) 
    at ReadStream._emitData (fs.js:1368:10) 
    at afterRead (fs.js:1350:10) 
    at Object.wrapper [as oncomplete] (fs.js:362:17) 

Process finished with exit code 1

我在 SO 上发现了一些帖子,似乎说静态行应该放在最后,所以这是我的 app.configure 供参考。

app.configure(function(){
    app.set('port', process.env.PORT || 3000);
    app.use(express.bodyParser({uploadDir:'./tmp'}));
    app.use(express.logger());
    app.use(express.methodOverride());
    app.use(express.cookieParser());
    app.use(express.session({
        secret  : "somesecret"
    }));
    // Initialize Passport!  Also use passport.session() middleware, to support
    // persistent login sessions (recommended).
    app.use(passport.initialize());
    app.use(passport.session());
    app.use(app.router);
    app.use(express.compress());
    app.use(express.static(path.join(__dirname, 'uploads')));
});
    ------------------------------------------------------------------------

任何帮助,将不胜感激!

4

0 回答 0