基于JWT身份验证和角色在Express中路由到多个Angular 7项目
我创建了一个Angular 7项目,它有多个不同角色的应用程序,如管理员,用户,编辑器等,每个都有不同的组件和视图。
登录用户将登陆其用户角色应用程序,其中任何访客用户将登陆具有登录和注册页面的“网站”应用程序。
我的问题是根据在身份验证期间确定的用户角色,使用express路由到不同的角度应用程序。这适用于一个角度应用程序,但不适用于多个角度应用程序
app.get('/', (req, res) => {
if (user.isAdmin) {
return res.sendFile(path.join(__dirname, '../../client/dist/admin/index.html'));
}
if (user.isUser) {
return res.sendFile(path.join(__dirname, '../../client/dist/user/index.html'));
}
return res.sendFile(path.join(__dirname, '../../client/dist/website/index.html'));
})
回答如下:
解决了它,只需将index.html重命名为不同的角色名称,如下图所示,
app.get('/', (req, res) => {
if (user.isAdmin) {
return res.sendFile(path.join(__dirname, '../../client/dist/admin/admin.html'));
}
if (user.isUser) {
return res.sendFile(path.join(__dirname, '../../client/dist/user/user.html'));
}
return res.sendFile(path.join(__dirname, '../../client/dist/website/website.html'));
})