I just added Hono to the http-
I just added Hono to the http-configuration here, and it seems nice. However, I am previously using
http.route
s, and these stop working. Is it impossible to mix and match Hono and the default routing scheme?3 Replies
when you create a new
HttpRouterwithHono(app)
your hono app becomes the primary router so the default http object would no longer automatically process unless hono specifically delegates to them.
you can do this by having Hono 'lookup' those old http routes for specific paths
you can do something like this
const http = httpRouter();
const app: HonoWithConvex<ActionCtx> = new Hono()
http.route("GET", "/old-api-endpoint", async (ctx) => {
return new Response("This is from the old httpRouter!");
});
app.get("/old-api-endpoint", async (c) => {
//use lookup
const result = http.lookup("/old-api-endpoint", "GET");
if (!result) {
return c.json({ error: "Old endpoint not found" }, 404);
}
const [httpAction] = result;
return httpAction(c.env, c.req.raw);
});
export default new HttpRouterWithHono(app);
Thanks, this is very helpful. I rewrote it all to use Hono in my case, it wasn't too much hassle, but perhaps someone else runs into the same issue.
welcome