ssh连接关闭后无法访问Node.js模块

时间:2014-05-25 20:18:21

标签: node.js express ssh passport.js

我已经使用Express和MongoDB在Node.js中编写了我的第一个webapp。作为基础,我使用了this example

在本地测试服务器时,一切都运行顺畅,并且首先在服务器上运行时(这是我通过SSH连接的Ubuntu服务器,并在断开连接后使用PM2保持进程运行) 。我遇到的问题是,当与服务器断开连接时,最初像魅力一样工作的网页会在我的脸上引发错误(请参阅下面的错误消息)。

Error: Failed to lookup view "index"
  at Function.app.render (/home/ubuntuserver/appname/node_modules/express/lib/application.js:489:17)
  at ServerResponse.res.render (/home/ubuntuserver/appname/node_modules/express/lib/response.js:755:7)
  at exports.index (/home/ubuntuserver/appname/routes/basic.js:4:7)
  at callbacks (/home/ubuntuserver/appname/node_modules/express/lib/router/index.js:161:37)
  at param (/home/ubuntuserver/appname/node_modules/express/lib/router/index.js:135:11)
  at pass (/home/ubuntuserver/appname/node_modules/express/lib/router/index.js:142:5)
  at Router._dispatch (/home/ubuntuserver/appname/node_modules/express/lib/router/index.js:170:5)
  at Object.router (/home/ubuntuserver/appname/node_modules/express/lib/router/index.js:33:10)
  at Context.next (/home/ubuntuserver/appname/node_modules/express/node_modules/connect/lib/proto.js:190:15)
  at Context.actions.pass (/home/ubuntuserver/appname/node_modules/passport/lib/passport/context/http/actions.js:77:8)
  at SessionStrategy.authenticate (/home/ubuntuserver/appname/node_modules/passport/lib/passport/strategies/session.js:67:10)
  at attempt (/home/ubuntuserver/appname/node_modules/passport/lib/passport/middleware/authenticate.js:243:16)
  at Passport.authenticate (/home/ubuntuserver/appname/node_modules/passport/lib/passport/middleware/authenticate.js:244:7)
  at next (/home/ubuntuserver/appname/node_modules/express/node_modules/connect/lib/proto.js:190:15)
  at Passport.initialize (/home/ubuntuserver/appname/node_modules/passport/lib/passport/middleware/initialize.js:69:5)
  at next (/home/ubuntuserver/appname/node_modules/express/node_modules/connect/lib/proto.js:190:15)
  at next (/home/ubuntuserver/appname/node_modules/express/node_modules/connect/lib/middleware/session.js:313:9)
  at /home/ubuntuserver/appname/node_modules/express/node_modules/connect/lib/middleware/session.js:330:9
  at /home/ubuntuserver/appname/node_modules/express/node_modules/connect/lib/middleware/session/memory.js:55:7
  at process._tickCallback (node.js:415:13)

节点进程似乎继续运行,但在断开SSH连接时出现问题。当通过SSH重新连接时,一切都会像往常一样直接开始工作。

任何idéas?

编辑: 我已经设法通过认识到PM2的集群模式不适用于Passport中使用的会话来减少错误。我现在使用-x启动PM2,并在断开SSH并尝试重新加载页面时在浏览器中出现以下错误:

Error: Failed to lookup view "index"
    at Function.app.render (/home/ubuntuserver/appname/node_modules/express/lib/application.js:489:17)
    at ServerResponse.res.render (/home/ubuntuserver/appname/node_modules/express/lib/response.js:755:7)
    at exports.index (/home/ubuntuserver/appname/routes/basic.js:4:7)
    at callbacks (/home/ubuntuserver/appname/node_modules/express/lib/router/index.js:161:37)
    at param (/home/ubuntuserver/appname/node_modules/express/lib/router/index.js:135:11)
    at pass (/home/ubuntuserver/appname/node_modules/express/lib/router/index.js:142:5)
    at Router._dispatch (/home/ubuntuserver/appname/node_modules/express/lib/router/index.js:170:5)
    at Object.router (/home/ubuntuserver/appname/node_modules/express/lib/router/index.js:33:10)
    at Context.next (/home/ubuntuserver/appname/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Context.actions.pass (/home/ubuntuserver/appname/node_modules/passport/lib/passport/context/http/actions.js:77:8)

1 个答案:

答案 0 :(得分:0)

我认为您需要在应用中明确指定app.set('views', __dirname + '/views'),以避免使用process.cwd()的明确默认值。 PM2改变了流程的当前工作目录或奇怪的东西,这可能是奇怪的事情。这可能不是关于您的代码,而是关于您的服务器环境的更多信息,因此很难远程排除故障。您可以尝试使用upstart而不是PM2。