Specification of `*` and '/*' in routing
See original GitHub issueI think the top-level *
and /*
behave a little differently than the documentation.
https://github.com/honojs/hono/releases/tag/v1.4.0
app.get('/', (c) => {
return c.text('foo')
}) // <--- stop process
app.use('*', middleware()) // <--- not dispached!!
Currently, in both TrieRouter and RegExpRouter, *
and /*
have higher precedence than /
.
( On TrieRouter, *
has the highest priority, /*
the next highest; on RegExpRouter, *
and /*
have the same priority. )
describe('star', () => {
const router = new TrieRouter<string>()
router.add('GET', '/', '/')
router.add('GET', '/*', '/*')
router.add('GET', '*', '*')
router.add('GET', '/x', '/x')
router.add('GET', '/x/*', '/x/*')
it.only('top', async () => {
const res = router.match('GET', '/')
expect(res).not.toBeNull()
expect(res.handlers).toEqual(['*', '/*', '/'])
})
it.only('Under a certain path', async () => {
const res = router.match('GET', '/x')
expect(res).not.toBeNull()
expect(res.handlers).toEqual(['*', '/*', '/x', '/x/*'])
})
})
describe('star', () => {
const router = new RegExpRouter<string>()
router.add('GET', '/', '/')
router.add('GET', '/*', '/*')
router.add('GET', '*', '*')
router.add('GET', '/x', '/x')
router.add('GET', '/x/*', '/x/*')
it.only('top', async () => {
const res = router.match('GET', '/')
expect(res).not.toBeNull()
expect(res.handlers).toEqual(['*', '/*', '/']) // => failed ['/*', '*', '/']
})
it.only('Under a certain path', async () => {
const res = router.match('GET', '/x')
expect(res).not.toBeNull()
expect(res.handlers).toEqual(['*', '/*', '/x', '/x/*'])
})
})
The scores appear to be as follows.
at TrieRouter
router.add('GET', '/', '/') // score: 1.1
router.add('GET', '/*', '/*') // score: 0.2
router.add('GET', '*', '*') // score: 0.3 - 1 => Approx. -0.7
at RegExpRouter
router.add('GET', '/', '/') // score: 1.1
router.add('GET', '/*', '/*') // score: 0.2 in RegExpRouter "/*" is an alias to "*".
router.add('GET', '*', '*') // score: 0.3
I think the current specification for TrieRouter is acceptable to us as users, so I can make it the official specification and adapt RegExpRouter to it. Alternatively, we can treat ‘/’ as an alias to '’, which would be the same as the RegExpRouter implementation.
Issue Analytics
- State:
- Created a year ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Routing Engine Specifications
Table 1 lists the current specifications for Routing Engines supported on M Series, MX Series, and T Series routers. Table 2 lists the...
Read more >Routing Policy Specification Language
The Routing Policy Specification Language (RPSL) is a language commonly used by Internet Service Providers to describe their routing policies.
Read more >Order Routing and Handling Data Technical Specification
The Technical Specification defines syntax of data elements, their contents, element arrangements, validation methods and dissemination methods ...
Read more >Network Routers Specifications
Help with Network Routers specifications: ; Number of Ports, The total number of networking ports which the network equipment provides. ; Search Logic:...
Read more >RFC 2280 - Routing Policy Specification Language (RPSL)
Routing Policy Specification Language (RPSL) (RFC 2280, January 1998; ... RPSL is extensible; new routing protocols and new protocol features can be ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@yusukebe We did it! I believe this will put an end to the long struggle in May. Thanks to user feedback, I’m sure we’ve landed on a very good spec!
@usualoma
I’ve merged two PRs #275, #276 to master. I tried the
graghql
scenario, it works well!If there is no problem, I’ll release v1.4.1.