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
egg-router-plus v2 sortRouters 方法使用了 trie-prefix-tree 处理 namespace prefix,但是 trie-prefix-tree 会对输入进行小写处理。如果 namespace prefix 存在大写字母,sortedPrefixes 的 prefix 就跟 namespaceRouters 不对应了,最终导致路由 404
https://github.com/eggjs/egg-router-plus/blob/cdfec8012f8e051a6b55d848cd4112191e566085/lib/router.js#L106-L110
function sortRouters(namespaceRouters) { const sortedPrefixes = trie(Array.from(namespaceRouters.keys())).getWords().reverse(); if (namespaceRouters.has('')) sortedPrefixes.push(''); return sortedPrefixes.map(prefix => [ prefix, namespaceRouters.get(prefix) ]); }
https://github.com/lyndseybrowning/trie-prefix-tree/blob/dcb48612606e4af37f9c1d240420bf9b13228f65/src/create.js#L8-L15
const trie = input.reduce((accumulator, item) => { item .toLowerCase() .split('') .reduce(append, accumulator); return accumulator; }, {});
例子
import { Application } from 'egg'; export default (app: Application) => { const { controller, router } = app; const subRouter = router.namespace('/A'); subRouter.get('/b', controller.home.test); };
访问 /A/a 会 404,访问 /a/a 会抛错 nodejs.TypeError: Cannot read properties of undefined (reading 'middleware') at node_modules/egg-router-plus/lib/router.js:20:25
The text was updated successfully, but these errors were encountered:
#4941 的根本原因
Sorry, something went wrong.
No branches or pull requests
egg-router-plus v2 sortRouters 方法使用了 trie-prefix-tree 处理 namespace prefix,但是 trie-prefix-tree 会对输入进行小写处理。如果 namespace prefix 存在大写字母,sortedPrefixes 的 prefix 就跟 namespaceRouters 不对应了,最终导致路由 404
https://github.com/eggjs/egg-router-plus/blob/cdfec8012f8e051a6b55d848cd4112191e566085/lib/router.js#L106-L110
https://github.com/lyndseybrowning/trie-prefix-tree/blob/dcb48612606e4af37f9c1d240420bf9b13228f65/src/create.js#L8-L15
例子
访问 /A/a 会 404,访问 /a/a 会抛错
nodejs.TypeError: Cannot read properties of undefined (reading 'middleware')
at node_modules/egg-router-plus/lib/router.js:20:25
The text was updated successfully, but these errors were encountered: