在基本Http Auth Express.js之后redirect

我想在我的php项目中使用express.js(如.htaccess和.htpasswd)来访问应用程序。

我正在使用http-auth

这是我的代码:

app.get('/', function(req, res) { basic.apply(req, res, function(username) { res.redirect(routes.index); }); }); 

问题是我得到一个错误:

500 TypeError:Object function(req,res){res.render('index',{title:'Express'}); }没有方法'indexOf'

没有authentication,

 app.get('/', routes.index); 

工作没有任何麻烦。

我想要一个中间件来读取我的索引,然后使用res.send()…可能会工作吗? 或者我错过了什么?

我认为res.redirect的参数需要是一个URLstring,对吧? 你似乎传递一个请求处理程序( function (req, res) {...} )。

我认为现在的使用模式是不同的

 // Authentication module. var auth = require('http-auth'); var basic = auth.basic({ realm: "Simon Area.", file: __dirname + "/../data/users.htpasswd" // gevorg:gpass, Sarah:testpass ... }); // Application setup. var app = express(); // Setup route. app.get('/', auth.connect(basic), routes.index);