Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filesystem based routing? #65

Closed
m1212e opened this issue Jul 19, 2023 · 16 comments
Closed

Filesystem based routing? #65

m1212e opened this issue Jul 19, 2023 · 16 comments

Comments

@m1212e
Copy link
Contributor

m1212e commented Jul 19, 2023

Hi,

I recently got into bun and was looking for a nice webframework which supports filesystem based routing. I like it because it - by design - enforces a clear structure for the project and you know where to find a certain route. Elysia does a few other things really really well in my opinion so I thought about using it but as far as I see it does not support fs based routes. Is this a thing you considered? Maybe also in a hybrid approach like I did here: https://github.com/m1212e/bun-fs-router-plugin

@itsyoboieltr
Copy link

+1, I would be really interested in this, I was just about to raise a proposal for this exactly.

@fecony
Copy link

fecony commented Jul 19, 2023

But Elysia doesn't really have frontend part so file based routing for api doesn't make sense..?

@itsyoboieltr
Copy link

But Elysia doesn't really have frontend part so file based routing for api doesn't make sense..?

This has nothing to do with frontend or not.

For reference, check Next.js route handler implementation for a file-system based api.

@fecony
Copy link

fecony commented Jul 19, 2023

But Elysia doesn't really have frontend part so file based routing for api doesn't make sense..?

This has nothing to do with frontend or not.

For reference, check Next.js route handler implementation for a file-system based api.

I didn't play with file based api, from one side looks like overhead of splitting everything
on the other looks like a good solution to extract those and make smaller

@ethanniser
Copy link

I don't think it would be too hard to make your own simple implementation
See the "However, it isn't too difficult to make a file-based router. Here's a file-based example code with builder:" part of the Waku docs

@wobsoriano
Copy link

Here's one - https://github.com/wobsoriano/elysia-autoroutes

@itsyoboieltr
Copy link

I also made an implementation of a file system routing plugin, based on groups, called the group router.

@m1212e
Copy link
Contributor Author

m1212e commented Aug 1, 2023

There are a few options, you could calculate the routes based on the current file path and just pass a helper function to spit out the correct relative path based on the file location, you could also utilize the bun.js macros/build plugins to set the correct path at build time. But what I could not get to work properly was the eden type safety. Since it works without code generation and TS does not support build time macros, I don't really seee a way to pull this off. Maybe one of the elysia devs knows how to implement something like this.

@ethanniser
Copy link

was just randomly reading the bun docs today and saw it has a native FileSystemRouter API that may be of use here

https://bun.sh/docs/api/file-system-router

@wobsoriano
Copy link

was just randomly reading the bun docs today and saw it has a native FileSystemRouter API that may be of use here

https://bun.sh/docs/api/file-system-router

elysia-autoroutes uses it!

@m1212e
Copy link
Contributor Author

m1212e commented Aug 7, 2023

@wobsoriano Did you manage to get eden types to work with it?

@wobsoriano
Copy link

No. That's the biggest challenge @m1212e - how do we combine types from the main ElysiaApp instance with the route files?

@m1212e
Copy link
Contributor Author

m1212e commented Aug 7, 2023

I don't see a way to do this without running some kind of process at development time.

@wobsoriano
Copy link

@m1212e what other meta framework do, like Nuxt, is to generate types for each route at dev time

@itsyoboieltr
Copy link

@m1212e what other meta framework do, like Nuxt, is to generate types for each route at dev time

@wobsoriano Actually, I tried to do something similar here (with not much success): #79

@SaltyAom
Copy link
Member

Closing as we have several plugins like Elysia Autoroute, Group Router and several other.

Elysia is not going to focus on File Based Routing at the moment.
All the discussion will be moving to #79 or feels free to open a new issue for dedicated topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants