Angularjs,Expressjs和passportjs用于服务器端的身份validation检查
我有一个Node.js应用程序,我已经使用了Yeoman脚手架Angular。 我也使用ExpressJS服务器端。
所以基本上我的app结构是:
app -->views --> more files server.js
结构比这更重,但这是为了保持简单。
基本上我在服务器端使用PassportJS进行身份validation。 路由目前正在通过AngularJS路由参数进行。
我现在遇到了一个问题,因为我需要使用中间件方法进行身份validation:
function ensureAuthenticated(req, res, next) { console.log('authenticate=' + req.isAuthenticated()); if (req.isAuthenticated()) { return next(); } res.redirect('/') }
我在服务器端创build了一个app.get
来检查用户是否试图进入pipe理页面而不login:
app.get('/admin', ensureAuthenticated, function(req, res){ console.log('get admin' + req.params); res.sendfile(__dirname + '/app/views/admin/users.html'); });
但它从来没有去的方法。 我究竟做错了什么?
任何build议将是伟大的。
if (!req.isAuthenticated()) { return res.send(401, 'User is not authorized'); } next();
它不工作的原因是因为在客户端configuration路由时,angularjs locationprovider未设置为htmlmode5。 添加了以下行:
$locationProvider.html5Mode(true);
这基本上从url中删除了“#”。
- 为什么Karma显示范围错误?
- 如何从Visual Studio Team System部署纯粹的Angular应用程序到Azure网站
- Express + Angular,总是发送html请求的索引文件,而不是api请求
- 如何在angular度使用npm模块?
- 如何从angular.js中的redirectURL捕获和获取价值?
- Axios Http客户端 – 如何构buildHttpurl与forms参数
- 使用Grunt和Node.js构buildAngularJS UI-Grid时遇到困难
- IBM PushNotification:Not Found – 目标资源“PushDevice”不存在
- 如何使用node.js将数组插入到mongodb中