Skip to content

fix: add opt-in appendAutoPrefix for directory auto prefixes#498

Open
SergioChan wants to merge 2 commits intofastify:mainfrom
SergioChan:fix-issue-205-append-auto-prefix
Open

fix: add opt-in appendAutoPrefix for directory auto prefixes#498
SergioChan wants to merge 2 commits intofastify:mainfrom
SergioChan:fix-issue-205-append-auto-prefix

Conversation

@SergioChan
Copy link
Contributor

Summary

  • add a new appendAutoPrefix autoload option (default false)
  • keep existing behavior by default (plugin.autoPrefix still overrides directory-derived prefixes)
  • when appendAutoPrefix: true, concatenate directory prefix + plugin.autoPrefix
  • add Issue autoPrefix overwrites directory path set by dirNameRoutePrefix #205 coverage to verify both default and opt-in behaviors
  • document the new option and update TypeScript definitions

Issue

Closes #205

Validation

  • node --test test/issues/205/test.js
  • node --test test/commonjs/basic.js

README.md Outdated

### `appendAutoPrefix` (optional) - Default: `false`

When `true`, `plugin.autoPrefix` is appended to the directory-derived prefix (from `dirNameRoutePrefix`) instead of replacing it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's totally unclear what this does from looking at this statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — addressed in commit c5cf899.

I rewrote this section to explicitly describe both modes (�ppendAutoPrefix: false vs rue) and included concrete resulting route paths so the behavior is easier to understand at a glance.

dir: path.join(__dirname, 'routes'),
appendAutoPrefix: true
})
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is not clear

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — updated in commit c5cf899.

The README example now uses a concrete directory + �utoPrefix setup and shows the exact resulting paths for both default mode and append mode.

@SergioChan
Copy link
Contributor Author

Thanks for the review — I pushed an update to clarify the behavior and example in README.

What changed:

  • Rewrote the appendAutoPrefix section to explicitly describe both modes (false vs true).
  • Added a concrete directory example showing routes/children/new-routes.js exporting autoPrefix = '/batch'.
  • Added explicit resulting route paths for both modes:
    • default: /your-parent-prefix/batch/entity
    • append mode: /your-parent-prefix/children/batch/entity

Validation:

  • node --test test/issues/205/test.js

If you want, I can also add a short one-line cross-reference from dirNameRoutePrefix to appendAutoPrefix for discoverability.

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

Successfully merging this pull request may close these issues.

autoPrefix overwrites directory path set by dirNameRoutePrefix

2 participants