基于 JWT 身份验证和 Role 路由到 Express 中的多个 Angular 7 个项目
Routing to multiple Angular 7 projects in Express based on JWT authentication and Role
我创建了一个 Angular 7 项目,它有多个应用程序用于不同的角色,例如管理员、用户、编辑器等。每个都有不同的组件和视图。
登录用户将登陆其用户角色应用程序,而任何访客用户将登陆具有登录和注册页面的 'website' 应用程序。
我的问题是根据身份验证期间确定的用户角色使用 express 路由到不同的 angular 应用程序。这适用于一个 angular 应用程序,但不适用于多个 angular 应用程序
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'));
})
我创建了一个 Angular 7 项目,它有多个应用程序用于不同的角色,例如管理员、用户、编辑器等。每个都有不同的组件和视图。
登录用户将登陆其用户角色应用程序,而任何访客用户将登陆具有登录和注册页面的 'website' 应用程序。
我的问题是根据身份验证期间确定的用户角色使用 express 路由到不同的 angular 应用程序。这适用于一个 angular 应用程序,但不适用于多个 angular 应用程序
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'));
})