Repository navigation
feat: support render function for json dirlist - #630
Conversation
|
Tested and verified against the directory listing test suite. Key points verified:
One small note: when returning a custom formatted JSON payload, if the user returns a pre-serialized JSON string (rather than an object or array), Fastify will default to |
Fixes fastify#221 Signed-off-by: Helmi Pradita <helmipraditaa@gmail.com>
00bfae8 to
c5fcc85
Compare
|
Great catch, thank you @SameRainbows! Added |
Puppo
left a comment
There was a problem hiding this comment.
Thanks for the PR! One compatibility regression needs addressing before this ships as a compatible feature; details inline.
Preserve existing list.render behavior for HTML listings when format is json (such as ?format=html override), and provide dedicated list.renderJson for customizing JSON listings. Signed-off-by: Helmi Pradita <helmipraditaa@gmail.com>
|
Thanks for the thorough review @Puppo! I have addressed this in commit
|
|
@Puppo — following up on your blocking review: all 17 checks are green on |
Head branch was pushed to by a user without write access
Summary
Adds an opt-in
list.renderJsonoption to customize the JSON directory listing.Closes #221
Changes
lib/dirList.js: when the resolved format isjsonandlist.renderJsonis a function, it is called with(dirs, files), the same argumentslist.renderreceives, and its return value is sent withContent-Type: application/json. The return value can be an object or an already serialized JSON string.ListJsonRenderinterface andrenderJson?: ListJsonRenderon the list options.list.renderJsonin thelist.formatsection.renderJsonreturning an object, returning a serialized string, and being used together withrender(including the?format=htmland?format=jsonURL overrides).Behavior
list.renderis unchanged and is still used only for thehtmlformat.list.renderJsonis omitted, the JSON response is still controlled bylist.jsonFormat, so existing configurations are not affected.?format=URL parameter keeps selecting between the two:htmluseslist.render,jsonuseslist.renderJsonwhen provided.renderJsonare already filtered by thedotfilespolicy.Notes
The initial version of this PR reused
list.renderfor JSON. That would have changed the response for existing setups withformat: 'json'and an HTMLrenderfunction, so it was replaced by the separate opt-in option after review.The expectation in the
render+renderJsontest was aligned with the newdotfiles: 'ignore'default after mergingmain(#620).Checklist
npm run test && npm run benchmark --if-presentand the Code of conduct