我在使用http-auth创建基于express的node.js应用程序时遇到问题模块。
可以为这个 http-auth 库创建中间件,我有以下代码:
//Configure Middlewares
logger.configure(function() {
//All output has content type json
logger.use(function(req, res, next) {
res.contentType('application/json');
next();
});
//Create digest auth middleware
logger.use(function(req, res, next){
digest.apply();
next();
});
});
应用此后,当我连接到网站时,出现此错误:
TypeError: Cannot read property 'headers' of undefined
有没有办法解决这个问题或者使用其他方法?
我需要对整个应用程序进行摘要身份验证。
最佳答案
我认为 apply() 需要请求对象(因此它无法读取 header );
尝试这个语法:
digest.apply(req, res, function(username) {
});
关于使用 HTTP-AUTH 的 Node.js Express,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15385819/