Skip to content

fileNameRoutePrefix #363

Open
Open
@tajnymag

Description

@tajnymag

Prerequisites

  • I have written a descriptive issue title
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions