-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Automatically wrap route files #54
Comments
You can already do what you desire: const routes = fs.readdirSync('path/to/routes/dir/')
routes.forEach(r => fastify.route(require(r))) The plugin pattern you show in your first example is merely the recommended method. It provided encapsulation and makes it easier to test individual routes. |
Thanks! That's neat! But that also means if we have an exception and need additional arguments, we'll have to handle that file outside the Also the automatic folder-2-route prefixing is lost here :( |
I thought this issue was on the core repo. I didn't realize it is in the autoload plugin repo. I know nothing of how this plugin works. |
Thanks anyway! Right now we don‘t have any special cases, so this might do the trick, but in the long run I think it‘s better to solve this in the autoloader. |
It would be great if you'd like to send a PR. |
I will. As mentioned, I can't get the tests to pass on |
Can you open a seperate issue with the error you are getting? |
Done. See #55 |
* feat: automatically wrap full routes into fastify plugins. Closes #54 * add documentation in readme * Update README.md * more concise checks for object * remove typeof Co-Authored-By: James Sumners <[email protected]>
🚀 Feature Proposal
We're migrating an API to fastify and somehow the boilerplate
feels a bit clunky. I'd like to propose just the route content in a file:
For most cases this is totally sufficient. If additional config/options are required, a regular plugin/route function can be exported.
Motivation
As mentioned above, the plugin structure feels a bit clunky in each and every file.
Example
The default type is a function and the new proposal would be an object (method is always required anyway), so I'm thinking somewhere along the lines of (https://github.com/fastify/fastify-autoload/blob/master/index.js#L110):
This is non-breaking, but to be safe it could also be flagged with an new option "wrapRoutes" or something like that.
I'm testing this locally, but I'm currently getting an error when running
npm test
?The text was updated successfully, but these errors were encountered: