Skip to content

feat: support globPattern option for custom route matching in non-wildcard mode - #609

Open
lx3133584 wants to merge 1 commit into
fastify:mainfrom
lx3133584:feat/support-custom-glob-pattern
Open

feat: support globPattern option for custom route matching in non-wildcard mode#609
lx3133584 wants to merge 1 commit into
fastify:mainfrom
lx3133584:feat/support-custom-glob-pattern

Conversation

@lx3133584

Copy link
Copy Markdown

Problem

When using wildcard: false to pre-register static routes, @fastify/static hardcodes the glob search pattern to '**/**', registering routes for every file found in the root directory. Users who want to restrict registered routes to specific extensions or subdirectories (e.g. '**/*.{css,js}') currently have to rely on globIgnore or custom routing workarounds.

Root Cause

glob in index.js was invoked with a hardcoded '**/**' pattern without exposing a configurable pattern option.

Fix

  • Support globPattern option in FastifyStaticOptions (defaulting to '**/**').
  • Pass opts.globPattern ?? '**/**' to glob when wildcard: false.
  • Update TypeScript definitions in types/index.d.ts and documentation in README.md.

Testing

  • Added test in test/glob-pattern.test.js verifying that custom globPattern only registers matching files.
  • Verified with node --test test/glob-pattern.test.js.

…dcard mode

Fixes fastify#178

Signed-off-by: Liang Xu <lx3133584@users.noreply.github.com>
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.

1 participant