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

Support route parameters in folder names #133

Closed
mcollina opened this issue Feb 22, 2021 · 11 comments Β· Fixed by #134
Closed

Support route parameters in folder names #133

mcollina opened this issue Feb 22, 2021 · 11 comments Β· Fixed by #134
Labels

Comments

@mcollina
Copy link
Member

πŸš€ Feature Proposal

We should support automatic routes for route params, as example /user/:userId/cart

β”œβ”€β”€ routes
β”‚   β”œβ”€β”€ user
β”‚   β”‚   β”œβ”€β”€ _userId
β”‚   β”‚       └── cart.js
β”œβ”€β”€ package.json
└── app.js

I would recommend we convert _ to : on loading.

@zekth
Copy link
Member

zekth commented Feb 22, 2021

I like this implementation and a good feature would be the generation of the scaffolding using fastify-cli.

@mcollina mcollina added the good first issue Good for newcomers label Feb 22, 2021
@jsumners
Copy link
Member

With as many customizations this module is getting for hooking into the algorithm, it might just be better to require an autoload.{json,yaml} file that has mappings and other configurations.

@mcollina
Copy link
Member Author

mcollina commented Feb 22, 2021

I tend to agree!

@polymathca polymathca mentioned this issue Feb 23, 2021
4 tasks
@polymathca
Copy link
Contributor

With as many customizations this module is getting for hooking into the algorithm, it might just be better to require an autoload.{json,yaml} file that has mappings and other configurations.

Were you thinking it would live in the root of the folder from which plugins are being loaded, or in a separate config folder elsewhere in the project?

@jsumners
Copy link
Member

With as many customizations this module is getting for hooking into the algorithm, it might just be better to require an autoload.{json,yaml} file that has mappings and other configurations.

Were you thinking it would live in the root of the folder from which plugins are being loaded, or in a separate config folder elsewhere in the project?

I imagine it would be a file within each directory that is loaded:

/project
  \__ /plugins
          \__ /plugin1
                 \__ autoload.yaml

πŸ€·β€β™‚οΈ I'm just making an observation. It could be an unworkable idea or not worth the effort. I really do not know.

@delvedor
Copy link
Member

I like using the folder names for generating the path, it's a well-established pattern in the node community.
Something like:


β”œβ”€β”€ routes
β”‚   β”œβ”€β”€ user
β”‚   β”‚   β”œβ”€β”€ [userId]
β”‚   β”‚       └── cart.js
β”œβ”€β”€ package.json
└── app.js

Configuration files could work as well, but yaml are very easy to misconfigure. Furthermore, at that point, you could just use the autoPrefix export πŸ€” .

@fox1t
Copy link
Member

fox1t commented Feb 23, 2021

I like the idea of using the filesystem since it is a pattern popularized by Next.js. I don't like having a separate folder for routes: usually, I divide the code by "services ."I think that using a yml provides more flexibility, though.

We might support both, starting from the filesystem thing?

@mcollina
Copy link
Member Author

FYI, I think the yml/json file is orthogonal to this issue, maybe we can split it?

@polymathca
Copy link
Contributor

I like using the folder names for generating the path, it's a well-established pattern in the node community.

I agree, I think the FS-based route hierarchy is easy to grasp, predictably follows the conventions you'd expect to see in a web application, and is handled very well by this plugin. I like @mcollina's suggestion of adding the option to include parameters, as I think that complements the functionality here quite well and doesn't add too many more new moving parts.

Configuration files could work as well, but yaml are very easy to misconfigure. Furthermore, at that point, you could just use the autoPrefix export πŸ€” .

FYI, I think the yml/json file is orthogonal to this issue, maybe we can split it?

I think that it would likely be more appropriate as its own plugin if it's not using the FS for routing, but I'm not sure what that would look like.

@climba03003 climba03003 linked a pull request Mar 11, 2021 that will close this issue
4 tasks
@arthur-fontaine
Copy link
Contributor

Is there a release date for this PR?

@mcollina
Copy link
Member Author

mcollina commented Apr 6, 2021

Thanks for the ping, I missed the last round of edit in the PR. It just miss docs.

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

Successfully merging a pull request may close this issue.

7 participants