fastify / fastify/fastify-autoload
fileNameRoutePrefix
- Dominant language
- JavaScript
- Stars
- 373
- Forks
- 77
- PR merge metrics
- No merged PRs in 30d
Description
### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the feature has not already been requested
### π Feature Proposal
Plugin could not only get their prefixes from their parent directories, but also from their filename.
The nature of the feature is very similar to the existing `dirNameRoutePrefix`. It could take either boolean or a function checking/parsing given filename.
### Motivation
It would make routes hierarchy much easier to digest and eliminate some code duplicity and hardcoded prefixes.
If I haven't missed the feature, right now, there's no easy way to declare routes prefix without either hardcoding it into the plugin file or to have a directory with an index file for each route.
### Example
Given this structure:
```
βββ plugins
β βββ hooked-plugin
β β βββ autohooks.mjs
β β βββ routes.js
β β βββ children
β β βββ commonjs.cjs
β β βββ module.mjs
β β βββ typescript.ts
β βββ single-plugin
β β βββ index.js
β β βββ utils.js
β βββ more-plugins
β β βββ commonjs.cjs
β β βββ module.mjs
β β βββ typescript.ts
β βββ another-plugin.js
βββ package.json
βββ app.js
```
fastify-autoload with `fileNameRoutePrefix: true, autoHooks: true` would generate these routes and prefix the leaf plugins accordingly:
```
/hooked-plugin/routes
/hooked-plugin/children/commonjs
/hooked-plugin/children/module
/hooked-plugin/children/typescript
/single-plugin
/single-plugin/utils
/more-plugins/commonjs
/more-plugins/module
/more-plugins/typescript
/another-plugin
```
Contributor guide
Assessment
This issue has not been assessed yet.