Skip to content

ListOptionsJsonFormat

reference
1 min readUpdated

Kind: Interface

Source: packages/platform-fastify/interfaces/external/fastify-static-options.interface.ts

Part of: Platform Fastify

ListOptionsJsonFormat configures directory listing output for the Fastify static file integration when JSON responses are required. It fixes the format discriminator to 'json' and requires a render function that generates the listing response.

Properties

PropertyType
format'json'
renderListRender

Diagram

mermaid
graph LR
  A[Fastify Static Directory Listing] --> B[ListOptionsJsonFormat]
  B --> C[format: 'json']
  B --> D[render: ListRender]
  D --> E[JSON Directory Listing Response]

Usage

ts
import type { ListOptionsJsonFormat } from './interfaces/external/fastify-static-options.interface';

const listOptions: ListOptionsJsonFormat = {
  format: 'json',
  render: (request, reply, files) => {
    return reply.send({
      files: files.map((file) => ({
        name: file.name,
        path: file.path,
      })),
    });
  },
};

// Pass listOptions to the Fastify static plugin configuration.

AI Coding Instructions

  • Set format exactly to 'json'; it acts as the discriminator for this listing configuration.
  • Always provide a render implementation compatible with the ListRender type.
  • Return or send a JSON-serializable response from render.
  • Use this interface only for directory listing behavior in the Fastify static integration.
  • Avoid mixing JSON-specific options with other listing format configurations.

Was this page helpful?

Download as PDF
ListOptionsJsonFormat — NestJS head-to-head