【发布时间】:2014-12-09 21:25:33
【问题描述】:
更新:为我的 successRedirect 使用不同的路径我已经成功地获得了对我的 GET 请求的 200 响应(请参见下面的代码)。不过,这只是我第一次上这条路线的时候。即便如此,浏览器也不会改变呈现的页面。即在我成功注册一个虚拟用户后,没有实际的重定向。
在对代码 304 进行了更多研究并进行了一些播放之后,这似乎是一个缓存问题,但到目前为止,这就是我所了解的。
获取/测试
app.get('/test', function(req, res) {
res.render('video-view.html');
});
// process the signup form
app.post('/signup', passport.authenticate('local-signup', {
successRedirect : '/test', // redirect to the secure profile section
failureRedirect : '/sign-up', // redirect back to the signup page if there is an error
failureFlash : true // allow flash messages
}));
在本地注册成功后,我很难让路由器正确重定向。我的 /config/passport.js 文件正确地向数据库添加了一行,并且似乎序列化了会话。它将用户返回到我的路由器,该路由器尝试重定向浏览器。查看我的控制台请求,我看到了这个不成功的请求:GET /home 304。
我已经为此工作了很长时间,但无法找到解决方案或解决问题。我的部分问题是我没有使用模板引擎 - 只是提供使用 angular.js 编写的 html。也许我没有正确配置它,但所有其他路由和功能都运行良好。有什么想法吗?
这是我的路由器代码:
var express = require('express');
module.exports = function(app, passport) {
app.get('/signup', function(req, res) {
// render the page and pass in any flash data if it exists
res.render('sign-up.html');
});
app.get('/home', function(req, res) {
res.render('video-view.html');
});
app.post('/signup', passport.authenticate('local-signup', {
successRedirect : '/home', // redirect to the secure profile section
failureRedirect : '/signup', // redirect back to the signup page if there is an error
failureFlash : true // allow flash messages
}));
};
我的服务器是这样设置的:
var express = require('express');
var app = express();
var port = process.env.PORT || 8080;
var passport = require('passport');
var flash = require('connect-flash');
require('./config/passport')(passport); // pass passport for configuration
app.configure(function() {
app.use(express.logger('dev')); // log every request to the console
app.use(express.cookieParser()); // read cookies (needed for auth)
app.use(express.bodyParser()); // get information from html forms
app.engine('html', require('ejs').renderFile);
app.use('/', express.static(__dirname + '/views'));
app.use(express.session({ secret: 'vidyapathaisalwaysrunning' } )); // session secret
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session
});
require('./app/routes.js')(app, passport); // load our routes and pass in our app and fully configured passport
app.listen(port);
【问题讨论】:
标签: angularjs node.js express passport.js