简体   繁体   English

静态文件Express JS上的权限路由

[英]Permission route on static file express JS

I am trying to authenticate user when he request some page that has static route. 当他请求具有静态路由的页面时,我正在尝试对用户进行身份验证。

app.use(express.static(__dirname + '/public/app');

Assume that the folder "templates" is under the path above ('/public/app/templates') : 假设文件夹“模板”位于上面的路径('/ public / app / templates')下:

app.get('/templates/permissionPage.html',function(req,res){
// if user is authorized.. reutrn the page,
else return 401..
});

my routing even don't enter the get request of the page. 我的路由甚至不输入页面的获取请求。 how can I handle that request? 如何处理该请求? I want that only specific users can access this page, although he got static route. 我希望只有特定用户才能访问此页面,尽管他获得了静态路由。

I am using angularJS on my front-end 我在前端使用angularJS

Thank you 谢谢

You have two options: 您有两种选择:

  1. Easy one: auth users on your web-server (proxy-server). 简单的一种:在您的Web服务器(代理服务器)上对用户进行身份验证。 Docs for Nginx , and for Apache NginxApache的文档
  2. Hard one: Build accounts and auth module for your app. 困难之一:为您的应用程序建立帐户和身份验证模块。 This will require work with storage (database), logic, and UI/UX. 这将需要使用存储(数据库),逻辑和UI / UX。 Or use ready solutions, like PassportJS 或使用现成的解决方案,例如PassportJS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM