当我初始化应用程序时,一切都很好,但是当我进入像“localhost/”这样的任何页面时,我得到这个(双:一次用于 index.html,一次用于请求的 javascript,见下文)错误:
TypeError: undefined is not a function
at hash (myapp\node_modules\express\node_modules\connect\lib\middleware\session.js:341:10)
at myapp\node_modules\express\node_modules\connect\lib\middleware\session.js:324:24
at Promise.module.exports.SessionStore.get (myapp\node_modules\session-mongoose\index.js:85:22)
at Promise.addBack (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:128:8)
at Promise.EventEmitter.emit (events.js:96:17)
at Promise.emit (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:66:38)
at Promise.complete (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:77:20)
at Query.findOne (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\query.js:1607:15)
at model.Document.init (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\document.js:229:11)
at model.init (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\model.js:196:36)
TypeError: undefined is not a function
at hash (myapp\node_modules\express\node_modules\connect\lib\middleware\session.js:341:10)
at myapp\node_modules\express\node_modules\connect\lib\middleware\session.js:324:24
at Promise.module.exports.SessionStore.get (myapp\node_modules\session-mongoose\index.js:85:22)
at Promise.addBack (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:128:8)
at Promise.EventEmitter.emit (events.js:96:17)
at Promise.emit (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:66:38)
at Promise.complete (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\promise.js:77:20)
at Query.findOne (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\query.js:1607:15)
at model.Document.init (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\document.js:229:11)
at model.init (myapp\node_modules\session-mongoose\node_modules\mongoose\lib\model.js:196:36)
这是我正在使用的代码:
var express = require('express');
var app = this.__app = express();
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({
store: this.__getSessionStore()
,secret: this.__secretSession
}));
app.post('/rpc', this.__manageRequest.bind(this)); // <-- this method is not even called
app.use("/client", express.static('./client/')); //
// gets the index.html, but files in subfolders (which exists) throws the second error in the double error
app.use("/", express.static('./client/production/build'));
app.listen(this.__appPort, this.__appIp);
我如何获得会话存储:
__getSessionStore: function(){
var express = require('express');
var app = this.__app;
var SessionMongoose = require("session-mongoose")(express);
var mongooseSessionStore = new SessionMongoose({
url: this.__mongodbUrl
,interval: 120000
});
return mongooseSessionStore;
}
Express 版本:3.0.0 Mongoose-sessions 版本:0.2.0
哈希方法中未定义的方法是“crc16”:在调试中也是未定义的
function hash(sess) {
return crc16(JSON.stringify(sess, function(key, val){
if ('cookie' != key) return val;
}));
}
在 crc 模块中,有一个 if(window) 并定义了窗口,问题是我看不到它的定义位置!因为这个窗口,它不会导出任何模块,因此函数是未定义的!我只是非常巧妙地删除了 if(window) 以始终导出到它的模块。好吧,那是 crc@0.2.0 模块 (https://github.com/alexgorbatchev/node-crc/pull/10) 中的一个错误,并且 express 需要该确切版本。
究竟是什么问题以及如何解决?多谢