cnodejs / nodeclub

:baby_chick:Nodeclub 是使用 Node.js 和 MongoDB 开发的社区系统
http://cnodejs.org/
MIT License
9.34k stars 3.12k forks source link

我本地启动很正常,但是一旦部署到服务器上,就会报下面这个错 #672

Open qxl1231 opened 8 years ago

qxl1231 commented 8 years ago

Connect 500 TypeError: Cannot read property 'user' of undefined at exports.authUser (/root/qxl/nodeclub/middlewares/auth.js:94:18) at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at initialize (/root/qxl/nodeclub/node_modules/passport/lib/middleware/initialize.js:53:5) at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at session (/root/qxl/nodeclub/node_modules/express-session/index.js:159:61) at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at compression (/root/qxl/nodeclub/node_modules/compression/index.js:218:5) at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at cookieParser (/root/qxl/nodeclub/node_modules/cookie-parser/index.js:68:5) at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at methodOverride (/root/qxl/nodeclub/node_modules/method-override/index.js:65:14) at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at urlencodedParser (/root/qxl/nodeclub/node_modules/body-parser/lib/types/urlencoded.js:88:40) at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at jsonParser (/root/qxl/nodeclub/node_modules/body-parser/lib/types/json.js:100:40) at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at frameguard (/root/qxl/nodeclub/node_modules/helmet/node_modules/frameguard/index.js:32:5) at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at responseTime (/root/qxl/nodeclub/node_modules/response-time/index.js:59:5) at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at /root/qxl/nodeclub/node_modules/loader-connect/connect.js:20:14 at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at exports.render (/root/qxl/nodeclub/middlewares/render.js:16:3) at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at module.exports (/root/qxl/nodeclub/middlewares/request_log.js:19:3) at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at expressInit (/root/qxl/nodeclub/node_modules/express/lib/middleware/init.js:33:5) at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at query (/root/qxl/nodeclub/node_modules/express/lib/middleware/query.js:49:5) at Layer.handle as handle_request at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/index.js:280:7 at Function.process_params (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:271:10) at Function.handle (/root/qxl/nodeclub/node_modules/express/lib/router/index.js:176:3) at EventEmitter.handle (/root/qxl/nodeclub/node_modules/express/lib/application.js:173:10) at Server.app (/root/qxl/nodeclub/node_modules/express/lib/express.js:38:9) at Server.emit (events.js:98:17) at HTTPParser.parser.onIncoming (http.js:2113:12) at HTTPParser.parserOnHeadersComplete as onHeadersComplete at Socket.socket.ondata (http.js:1971:22) at TCP.onread (net.js:528:27)

alsotang commented 8 years ago

redis 和 mongodb 都装了吗?

2015-12-30 10:33 GMT+08:00 johnson notifications@github.com:

Connect 500 TypeError: Cannot read property 'user' of undefined at exportsauthUser (/root/qxl/nodeclub/middlewares/authjs:94:18) at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at initialize (/root/qxl/nodeclub/node_modules/passport/lib/middleware/initializejs:53:5) at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at session (/root/qxl/nodeclub/node_modules/express-session/indexjs:159:61) at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at compression (/root/qxl/nodeclub/node_modules/compression/indexjs:218:5) at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at cookieParser (/root/qxl/nodeclub/node_modules/cookie-parser/indexjs:68:5) at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at methodOverride (/root/qxl/nodeclub/node_modules/method-override/indexjs:65:14) at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at urlencodedParser (/root/qxl/nodeclub/node_modules/body-parser/lib/types/urlencodedjs:88:40) at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at jsonParser (/root/qxl/nodeclub/node_modules/body-parser/lib/types/jsonjs[image: :100:]40) at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at frameguard (/root/qxl/nodeclub/node_modules/helmet/node_modules/frameguard/indexjs:32:5) at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at responseTime (/root/qxl/nodeclub/node_modules/response-time/indexjs:59:5) at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at /root/qxl/nodeclub/node_modules/loader-connect/connectjs:20:14 at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at exportsrender (/root/qxl/nodeclub/middlewares/renderjs:16:3) at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at moduleexports (/root/qxl/nodeclub/middlewares/request_logjs:19:3) at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at expressInit (/root/qxl/nodeclub/node_modules/express/lib/middleware/initjs:33:5) at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at query (/root/qxl/nodeclub/node_modules/express/lib/middleware/queryjs:49:5) at Layerhandle as handle_request http:///root/qxl/nodeclub/node_modules/express/lib/router/layerjs:95:5 at trim_prefix (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:312:13) at /root/qxl/nodeclub/node_modules/express/lib/router/indexjs:280:7 at Functionprocess_params (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:330:12) at next (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:271:10) at Functionhandle (/root/qxl/nodeclub/node_modules/express/lib/router/indexjs:176:3) at EventEmitterhandle (/root/qxl/nodeclub/node_modules/express/lib/applicationjs:173:10) at Serverapp (/root/qxl/nodeclub/node_modules/express/lib/expressjs:38:9) at Serveremit (eventsjs:98:17) at HTTPParserparseronIncoming (httpjs:2113:12) at HTTPParserparserOnHeadersComplete as onHeadersComplete at Socketsocketondata (httpjs:1971:22) at TCPonread (netjs:528:27)

— Reply to this email directly or view it on GitHub https://github.com/cnodejs/nodeclub/issues/672.

qxl1231 commented 8 years ago

都装了,,如果没装肯定会报redis or mongodb 连接异常,这个看报错,应该是session获取不到user,然后就报的错

leizongmin commented 8 years ago

session-redis 连接不成功不会报错,建议再次确认一下本地 redis 和 mongodb 服务是否正常,以及 nodeclub 中相应的配置信息是否正确。

leizongmin commented 8 years ago

所以存储引擎无法连接成功时不会报错,其表现是没有 req.session ,接下来程序中任何读取 req.session 上的变量的操作都会报错 TypeError: Cannot read property 'xxx' of undefined

qxl1231 commented 8 years ago

[root@iZ23wefo5t9Z nodeclub]# redis-server 10153:C 30 Dec 12:28:21.437 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf 10153:M 30 Dec 12:28:21.438 # Creating Server TCP listening socket *:6379: bind: Address already in use [root@iZ23wefo5t9Z nodeclub]# mongod mongod --help for help and startup options Wed Dec 30 12:31:34.291 [initandlisten] MongoDB starting : pid=10163 port=27017 dbpath=/data/db/ 64-bit host=iZ23wefo5t9Z Wed Dec 30 12:31:34.291 [initandlisten] db version v2.4.14 Wed Dec 30 12:31:34.291 [initandlisten] git version: nogitversion Wed Dec 30 12:31:34.291 [initandlisten] build info: Linux buildvm-24.phx2.fedoraproject.org 3.19.5-200.fc21.x86_64 #1 SMP Mon Apr 20 19:51:56 UTC 2015 x86_64 BOOST_LIB_VERSION=1_41 Wed Dec 30 12:31:34.291 [initandlisten] allocator: tcmalloc Wed Dec 30 12:31:34.291 [initandlisten] options: {} Wed Dec 30 12:31:34.292 [initandlisten] exception in initAndListen: 10310 Unable to lock file: /data/db/mongod.lock. Is a mongod instance already running?, terminating Wed Dec 30 12:31:34.292 dbexit: Wed Dec 30 12:31:34.292 [initandlisten] shutdown: going to close listening sockets... Wed Dec 30 12:31:34.292 [initandlisten] shutdown: going to flush diaglog... Wed Dec 30 12:31:34.292 [initandlisten] shutdown: going to close sockets... Wed Dec 30 12:31:34.292 [initandlisten] shutdown: waiting for fs preallocator... Wed Dec 30 12:31:34.292 [initandlisten] shutdown: lock for final commit... Wed Dec 30 12:31:34.292 [initandlisten] shutdown: final commit... Wed Dec 30 12:31:34.292 [initandlisten] shutdown: closing all files... Wed Dec 30 12:31:34.292 [initandlisten] closeAllFiles() finished Wed Dec 30 12:31:34.292 dbexit: really exiting now [root@iZ23wefo5t9Z nodeclub]# node ap api/ api_router_v1.js app.js
[root@iZ23wefo5t9Z nodeclub]# node app.js NodeClub listening on port 3003 God bless love.... You can debug your app with http://121.40.56.245:3003

Started 2015-12-30T04:32:15.770Z GET / 58.214.28.226 TypeError: Cannot read property 'user' of undefined

qxl1231 commented 8 years ago

以上是mongodb和redis-server的命令后的响应.说明都是起着的呀

alsotang commented 8 years ago

redis 报错这边,我专门做了一个检测逻辑的,当 redis 服务器不存在的时候,服务器直接 process.exit(1)。

这个报错看起来确实是 req.session 为空时候的报错

2015-12-30 12:34 GMT+08:00 johnson notifications@github.com:

以上是mongodb和redis-server的命令后的响应.说明都是起着的呀

— Reply to this email directly or view it on GitHub https://github.com/cnodejs/nodeclub/issues/672#issuecomment-167934294.

calidion commented 8 years ago

redis部分的连接代码有问题。 参考一下我修改的版本,修复了redis的配置问题: https://github.com/node-weixin/nodeweixinforum

qxl1231 commented 8 years ago

能否合并到主版本上哈,跟atang 商量下?

calidion commented 8 years ago

@qxl1231 我删除了不少东西。应该无法合回来。

alsotang commented 8 years ago

?? 你说的问题是,我这里不支持redis密码吗?

https://github.com/node-weixin/nodeweixinforum/blob/master/common/redis.js 我看这份文件跟我现在的区别就是这一点。

2016-01-19 17:12 GMT+08:00 Eric notifications@github.com:

@qxl1231 https://github.com/qxl1231 我删除了不少东西。应该无法合回来。

— Reply to this email directly or view it on GitHub https://github.com/cnodejs/nodeclub/issues/672#issuecomment-172783009.

calidion commented 8 years ago

@alsotang 是的。我发现的问题是这个问题。 楼主所说的问题可能是其它问题, 我测试时也出现过。