0

我刚从 Derby 开始,然后开始集成 MongoDB 和 derby-auth。但是,我遇到了麻烦,无法弄清楚。以下代码返回其下方的堆栈跟踪。找出导致错误的原因非常困难。这是使用 derby -c new project 生成的新项目。我所知道的是它与这auth.store(store)条线有关。

更新:我example/在 derby-auth 中也遇到了这个问题,但仅限于我的第一个请求,所以我猜这与数据库连接有关。

http = require 'http'
path = require 'path'
express = require 'express'
gzippo = require 'gzippo'
derby = require 'derby'
app = require '../app'
serverError = require './serverError'
auth = require('derby-auth')
MongoStore = require('connect-mongo')(express)


## SERVER CONFIGURATION ##

expressApp = express()
server = http.createServer expressApp

derby.use(require 'racer-db-mongo')
derby.use(derby.logPlugin)
store = derby.createStore
  listen: server
  db:
    type: 'Mongo'
    uri: 'mongodb://localhost/admin'

module.exports = server
auth.store(store)

ONE_YEAR = 1000 * 60 * 60 * 24 * 365
root = path.dirname path.dirname __dirname
publicPath = path.join root, 'public'

# Authentication strategies (providers actually)
strategies =
  facebook:
    strategy: require('passport-facebook').Strategy
    conf:
      clientID: 'boo'
      clientSecret: 'boo'

# Authentication optionss
options =
  domain: (if process.env.NODE_ENV is 'production' then "http://www.mydomain.com" else "http://localhost:3000" )

expressApp
  .use(express.favicon())
  # Gzip static files and serve from memory
  .use(gzippo.staticGzip publicPath, maxAge: ONE_YEAR)
  # Gzip dynamically rendered content
  .use(express.compress())

  # Uncomment to add form data parsing support
  .use(express.bodyParser())
  .use(express.methodOverride())

  # Uncomment and supply secret to add Derby session handling
  # Derby session middleware creates req.session and socket.io sessions
  .use(express.cookieParser())
  .use(store.sessionMiddleware
    secret: 'mooo'
    cookie: {maxAge: ONE_YEAR}
    store: new MongoStore({ url: 'mongodb://localhost/admin' })
  )

  # Adds req.getModel method
  .use(store.modelMiddleware())

  # Authentication
  .use(auth.middleware(strategies, options))

  # Creates an express middleware from the app's routes
  .use(app.router())
  .use(expressApp.router)
  .use(serverError root)


## SERVER ONLY ROUTES ##

expressApp.all '*', (req) ->
  throw "404: #{req.url}"

堆栈跟踪:

TypeError: Cannot read property '_at' of undefined
    at Model.mixin.proto._createRef ($derbypath/node_modules/derby/node_modules/racer/lib/refs/index.js:158:20)
    at Model.mixin.proto.ref ($derbypath/node_modules/derby/node_modules/racer/lib/refs/index.js:124:19)
    at $derbypath/lib/app/index.js:18:11
    at Object.fail ($derbypath/node_modules/derby/node_modules/racer/lib/descriptor/descriptor.Model.js:268:21)
    at Object.module.exports.events.middleware.middleware.subscribe.add._res.fail ($derbypath/node_modules/derby/node_modules/racer/lib/pubSub/pubSub.Store.js:80:40)
    at module.exports.events.init.store.eachContext.context.guardReadPath.context.guardReadPath ($derbypath/node_modules/derby/node_modules/racer/lib/accessControl/accessControl.Store.js:25:26)
    at next ($derbypath/node_modules/derby/node_modules/racer/lib/middleware.js:7:26)
    at guard ($derbypath/node_modules/derby/node_modules/racer/lib/accessControl/accessControl.Store.js:156:36)
    at next ($derbypath/node_modules/derby/node_modules/racer/lib/middleware.js:7:26)
    at run ($derbypath/node_modules/derby/node_modules/racer/lib/middleware.js:10:12)
    at $derbypath/node_modules/derby/node_modules/racer/lib/pubSub/pubSub.Store.js:88:11
    at next ($derbypath/node_modules/derby/node_modules/racer/lib/middleware.js:7:26)
    at Object.run [as subscribe] ($derbypath/node_modules/derby/node_modules/racer/lib/middleware.js:10:12)
    at module.exports.server._addSub ($derbypath/node_modules/derby/node_modules/racer/lib/descriptor/descriptor.Model.js:237:26)
    at Object.Promise.on ($derbypath/node_modules/derby/node_modules/racer/lib/util/Promise.js:29:7)
    at Model.module.exports.server._addSub ($derbypath/node_modules/derby/node_modules/racer/lib/descriptor/descriptor.Model.js:221:29)
    at subscribe ($derbypath/node_modules/derby/node_modules/racer/lib/descriptor/descriptor.Model.js:267:9)
    at Model.module.exports.proto.subscribe ($derbypath/node_modules/derby/node_modules/racer/lib/descriptor/descriptor.Model.js:106:7)
    at $derbypath/lib/app/index.js:17:16
    at onRoute ($derbypath/node_modules/derby/lib/derby.server.js:69:7)
    at app.router ($derbypath/node_modules/derby/node_modules/tracks/lib/index.js:96:16)
    at callbacks ($derbypath/node_modules/derby/node_modules/tracks/node_modules/express/lib/router/index.js:160:37)
    at param ($derbypath/node_modules/derby/node_modules/tracks/node_modules/express/lib/router/index.js:134:11)
    at param ($derbypath/node_modules/derby/node_modules/tracks/node_modules/express/lib/router/index.js:131:11)
    at pass ($derbypath/node_modules/derby/node_modules/tracks/node_modules/express/lib/router/index.js:141:5)
    at Router._dispatch ($derbypath/node_modules/derby/node_modules/tracks/node_modules/express/lib/router/index.js:169:5)
    at dispatch ($derbypath/node_modules/derby/node_modules/tracks/lib/index.js:43:21)
    at Object.middleware [as handle] ($derbypath/node_modules/derby/node_modules/tracks/lib/index.js:58:7)
    at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at app.use.fn ($derbypath/node_modules/express/lib/application.js:121:9)
    at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:127:23)
    at pass ($derbypath/node_modules/express/lib/router/index.js:107:24)
    at Router._dispatch ($derbypath/node_modules/express/lib/router/index.js:170:5)
    at Object.router ($derbypath/node_modules/express/lib/router/index.js:33:10)
    at Context.next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Context.actions.pass ($derbypath/node_modules/derby-auth/node_modules/passport/lib/passport/context/http/actions.js:77:8)
    at SessionStrategy.authenticate ($derbypath/node_modules/derby-auth/node_modules/passport/lib/passport/strategies/session.js:52:10)
    at attempt ($derbypath/node_modules/derby-auth/node_modules/passport/lib/passport/middleware/authenticate.js:243:16)
    at Passport.authenticate ($derbypath/node_modules/derby-auth/node_modules/passport/lib/passport/middleware/authenticate.js:244:7)
    at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Passport.initialize ($derbypath/node_modules/derby-auth/node_modules/passport/lib/passport/middleware/initialize.js:69:5)
    at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.handle ($derbypath/node_modules/derby-auth/index.js:71:16)
    at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.module.exports [as handle] ($derbypath/node_modules/derby-auth/node_modules/connect-flash/lib/flash.js:20:5)
    at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.expressInit [as handle] ($derbypath/node_modules/express/lib/middleware.js:31:5)
    at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.query [as handle] ($derbypath/node_modules/express/node_modules/connect/lib/middleware/query.js:44:5)
    at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Function.app.handle ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:198:3)
    at Object.app.use.fn [as handle] ($derbypath/node_modules/express/lib/application.js:117:11)
    at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.modelMiddleware [as handle] ($derbypath/node_modules/derby/node_modules/racer/lib/session/session.Store.js:119:5)
    at next ($derbypath/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at store.get.next ($derbypath/node_modules/derby/node_modules/racer/node_modules/connect/lib/middleware/session.js:313:9)
    at $derbypath/node_modules/derby/node_modules/racer/node_modules/connect/lib/middleware/session.js:337:9
    at sessStore.load.sessStore.get ($derbypath/node_modules/derby/node_modules/racer/lib/session/session.Store.js:262:11)
    at process.startup.processNextTick.process._tickCallback (node.js:245:9)
4

1 回答 1

0

在 $derbypath/lib/app/index.js:18:11 检查这一行

于 2013-04-19T06:45:19.763 回答