We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
server/src/routes/index.js中
// 注册路由中间件, 需要在注册路由地址之前使用 loginRouter.use(PrivilegeChecker.checkLogin) loginProjectRouter.use(PrivilegeChecker.checkPrivilege)
注册中间件在注册路由地址之前使用,的确会提前检测login和privilege,但是对于应该返回404的路由,就无法正常通过了。
建议优化: 注册中间件的时机,应该注册路由地址之后,加入URL进行过滤。 代码如下:
for (let url of Object.keys(routerConfigMap)) { let routerConfig = routerConfigMap[url]; if (routerConfig.needLogin) { // 需要登录 loginRouter.use(url, PrivilegeChecker.checkLogin); if (routerConfig.needProjectId) { // 需要校验项目权限 loginProjectRouter.use(url, PrivilegeChecker.checkPrivilege); Logger.log(`需要登录,也需要检验项目权限(Method: ${routerConfig.methodType}) =>`, url); registerRouterByMethod(loginProjectRouter, routerConfig, url) } else { // 不需要校验项目权限 Logger.log(`需要登录,但不需要检验项目权限(Method: ${routerConfig.methodType}) =>`, url) registerRouterByMethod(loginCommonRouter, routerConfig, url) } } else { Logger.log(`不需要登录(Method: ${routerConfig.methodType}) =>`, url) // 不需要登录 registerRouterByMethod(withoutLoginRouter, routerConfig, url) } }
The text was updated successfully, but these errors were encountered:
404路由是在前端处理的,没有复现出404路由无法正常通过的问题,或许可以给出复现此问题的步骤
Sorry, something went wrong.
复现说明:
/api/user/detail 由于已经注册该路由,规定需要登录,不需要检测项目ID,用postman请求,会返回下图,符合预期。
假设我现在请求了一个没有注册过的路由,/api/abc/abc,前端在写接口的时候也常有不小心拼写错误的情况,预期应该返回404,告知该路由不存在。但是用postman请求,仍然会返回'请先登录',不符合实际预期,最好是返回404错误
No branches or pull requests
server/src/routes/index.js中
注册中间件在注册路由地址之前使用,的确会提前检测login和privilege,但是对于应该返回404的路由,就无法正常通过了。
建议优化: 注册中间件的时机,应该注册路由地址之后,加入URL进行过滤。
代码如下:
The text was updated successfully, but these errors were encountered: