H
Hono2w ago
michał

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
14 Replies
Hurby
Hurby2w ago
I usually export my routes in an object with route name and then loop over to add all the routes.
michał
michałOP2w ago
@Hurby what do you mean by exporting in an object?
Hurby
Hurby2w ago
so let's say I have auth related routes in auth.route.ts
No description
Hurby
Hurby2w ago
I import and add them into objects of array
No description
Hurby
Hurby2w ago
so in the root index.ts I can just do this
No description
Hurby
Hurby2w ago
@michał idk if I am clear xd
michał
michałOP2w ago
but woudln't I have to manually list all of my routes in defaultRoutes anyway? @Hurby
Hurby
Hurby2w ago
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
michał
michałOP2w ago
ah gotcha, I don't really mind it being ungrouped, but wanted to make it completely automatic Thank you anyways ❤️ @Hurby
Hurby
Hurby2w ago
yw also do you import these(createUser, loginUser) as separate functions?
michał
michałOP2w ago
yea I have them in separate files
Hurby
Hurby2w ago
why don't you just group them in one hono instance and then export them
Hurby
Hurby2w ago
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.
michał
michałOP2w ago
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 🙂
Want results from more Discord servers?
Add your server