`.route()` grouping breaks trigger event routes.
Closed this issue · 2 comments
NamesMT commented
Trigger event routes/paths support works as a simple wrapper that gets the eventSource
, and transforms it into method:TRIGGER path:eventSource
Request for Hono to process, we would then register routes on TRIGGER
method.
For it to work perfectly, the paths of the eventSource
should never intended to be prefixed, i.e: TRIGGER
method should never be prefixed
Currently Hono doesn't provide any (and I can't find hack-able) way to get or skip the prefix of .route()
grouping, so, Hono instances with trigger events would break after getting grouped with .route()
NamesMT commented
Some possible solutions:
- Solution 1: update to Hono's core, providing some way to get/skip the prefix of
.route()
grouping for specific routes/methods. - Solution 2: Agree to never use path delimiter "/" in
eventSource
, we could then provide a helper function to loop through the top-levelapp.router.routes
and just return the string after the last "/" onTRIGGER
method, we only need to run it once. - Solution 3: A helper function that receives both the top-level app instance and the instance that contains the trigger event routes, would automatically detect and remove the prefixed path, we need to pass in all instances that registered the trigger event routes, also a bit high count of loops and search.
- Solution 4: Register the trigger event routes in a separate instance and
route()
them without a prefix, this increases the instances and export/import count.