Can I automatically serve endpoints from a folder?
Hey, I use Hono and Bun and wondering if I can automatically create routing for my endpoint instead of listing them one by one?
14 Replies
I usually export my routes in an object with route name and then loop over to add all the routes.
@Hurby what do you mean by exporting in an object?
so let's say I have auth related routes in auth.route.ts
I import and add them into objects of array
so in the root index.ts I can just do this
@michał idk if I am clear xd
but woudln't I have to manually list all of my routes in defaultRoutes anyway? @Hurby
yea but you can group them if they have same base route( /auth in my case) and it is much more cleaner to write this way imo
ah gotcha, I don't really mind it being ungrouped, but wanted to make it completely automatic
Thank you anyways ❤️
@Hurby
yw
also do you import these(createUser, loginUser) as separate functions?
yea I have them in separate files
why don't you just group them in one hono instance and then export them
Best Practices - Hono
Web framework built on Web Standards for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
I didn't think of it because I will probably not have so many categories of routing to group them, but If it will scale I will do it, thank you 🙂