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?
![No description](https://cdn.answeroverflow.com/1310321700277063680/A33C20B7-FD3B-401F-84D6-6C6E730D5F54.png)
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
![No description](https://cdn.answeroverflow.com/1310333008460382340/image.png)
I import and add them into objects of array
![No description](https://cdn.answeroverflow.com/1310333189926944830/image.png)
so in the root index.ts I can just do this
![No description](https://cdn.answeroverflow.com/1310333380092756008/image.png)
@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 🙂