yarrichar
yarrichar15mo ago

Has anyone got Hono with Convex working

Has anyone got Hono with Convex working? Trying to follow this article: https://stack.convex.dev/hono-with-convex but running into errors:
const mostSpecificHandler = match.handlers[match.handlers.length - 1];
const mostSpecificHandler = match.handlers[match.handlers.length - 1];
The above line of the lookup method seems broken - match doesnt have a property handlers. Is there another way of adding dynamic / wildard routes to convex? I.e. URLs of the form /user/:id
2 Replies
sshader
sshader15mo ago
Looks like this needs to be updated to work with newer versions of hono. I'll work on updating our examples. I think the fix is something like
const handlersAndRoutes = match[0]
const mostSpecificHandler = handlersAndRoutes[handlersAndRoutes.length - 1][0][0];
const handlersAndRoutes = match[0]
const mostSpecificHandler = handlersAndRoutes[handlersAndRoutes.length - 1][0][0];
But also this method is mostly doing some work to make the requests show up nicely in Convex dashboard logs. Changing lookup to just return [this._handler, normalizeMethod(method), path] as const; will work, but the dashboard will show stuff like GET /users/123 instead of GET /users/:userId
yarrichar
yarricharOP15mo ago
Thanks for getting back to me. Your fix worked. I thought it wasn't for a second because I was getting a 404 when hitting the endpoint. It turns out that was because I wasn't returning anything from my request handler. Not sure who is responsible for the 404 (convex or hono), but better messaging around that would have been nice. Anyway, thanks again!

Did you find this page helpful?