Skip to content

fix: preserve directory index root priority when wildcard is false - #618

Merged
Tony133 merged 3 commits into
fastify:mainfrom
TalhaHunter101:fix/multi-root-index-priority
Nov 13, 2026
Merged

Tony133 merged 3 commits into
fastify:mainfrom
TalhaHunter101:fix/multi-root-index-priority

Conversation

@TalhaHunter101

Copy link
Copy Markdown
Contributor

Fixes #617

Description

When wildcard: false and multiple root directories are configured, indexDirs tracks the directory path and the corresponding root to serve directory index routes.

However, in index.js:

const key = path.posix.basename(route)
if (indexes.has(key) && !indexDirs.has(key)) {
  indexDirs.set(path.posix.dirname(route), rootPath)
}

The condition checked !indexDirs.has(key) against the basename instead of checking against the directory path (path.posix.dirname(route)). Because the basename string was not the Map key of indexDirs, subsequent lower-priority roots with index files would overwrite higher-priority roots in indexDirs.

This PR:

  • Changes the check to !indexDirs.has(dir) where dir = path.posix.dirname(route).
  • Adds a unit test verifying multi-root directory index priority with wildcard: false.
  • All tests pass with 100% code coverage.

Signed-off-by: Talha Shafeeq <talha.shafeeq.ts@gmail.com>
Comment thread test/static.test.js Resolved
Signed-off-by: Talha Shafeeq <talha.shafeeq.ts@gmail.com>

@Tony133 Tony133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@Tony133
Tony133 merged commit ce8a807 into fastify:main Nov 13, 2026
17 checks passed
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.

bug: directory index route root priority is overwritten when wildcard is false

3 participants