带有HTTP-AUTH的node.js Express

我用http-auth模块创build基于express的node.js应用程序有问题。

这是一个可能的创build这个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 

有没有解决这个问题或使用其他方法?

我需要整个应用程序的摘要validation。

我认为apply()期待的请求对象(因此它不能读取标题);

尝试这个语法:

 digest.apply(req, res, function(username) { }); 

你应该使用正确的模式 :

 // Authentication module. var auth = require('http-auth'); var digest = auth.digest({ realm: "Simon Area.", file: __dirname + "/../data/users.htdigest" }); // Configure Middlewares logger.configure(function() { // Create digest auth middleware logger.use(auth.connect(digest)); // All output has content type json. logger.use(function(req, res, next) { res.contentType('application/json'); next(); }); });