Skip to content

feat: support render function for json directory listings - #608

Open
lx3133584 wants to merge 1 commit into
fastify:mainfrom
lx3133584:feat/dir-list-json-render
Open

feat: support render function for json directory listings#608
lx3133584 wants to merge 1 commit into
fastify:mainfrom
lx3133584:feat/dir-list-json-render

Conversation

@lx3133584

Copy link
Copy Markdown

Problem

When list.format is set to json (or default JSON mode), configuring a custom list.render function was ignored for JSON responses and only invoked when querying with ?format=html.

Root Cause

dirList.send handled list.render exclusively inside the format === 'html' branch, skipping user-defined custom directory rendering for JSON output.

Fix

  • Updated dirList.send to invoke options.render(dirs, files, format) for JSON listings when list.render is provided.
  • Added ListJsonRender and ListFormat to TypeScript declarations and extended test definitions in types/index.tst.ts.
  • Added documentation and examples for JSON rendering in README.md.

Testing

  • Added unit tests in test/dir-list.test.js verifying custom JSON rendering and format argument propagation.
  • Verified all 348 unit tests pass with 100% line, statement, and branch coverage, and typecheck passes cleanly.

Fixes fastify#221

Signed-off-by: Liang Xu <lx3133584@users.noreply.github.com>
@lx3133584
lx3133584 force-pushed the feat/dir-list-json-render branch from e8f6a7a to 7fe432b Compare August 27, 2026 10:11
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