Kind: Interface
Source: packages/platform-fastify/interfaces/external/fastify-static-options.interface.ts
Part of: Platform Fastify
ListOptionsHtmlFormat configures directory listing output in HTML format for Fastify static file serving. It requires format to be the literal value 'html' and provides a render function responsible for generating the HTML response content.
Properties
| Property | Type |
|---|---|
format | 'html' |
render | ListRender |
Diagram
mermaidgraph LR A[Fastify Static Directory Listing] --> B[ListOptionsHtmlFormat] B --> C[format: 'html'] B --> D[render: ListRender] D --> E[Generated HTML Response]
Usage
tsimport type { ListOptionsHtmlFormat } from './interfaces/external/fastify-static-options.interface';
const directoryListingOptions: ListOptionsHtmlFormat = {
format: 'html',
render: (directories, files) => {
const directoryItems = directories
.map((directory) => `<li><a href="${directory.href}">${directory.name}/</a></li>`)
.join('');
const fileItems = files
.map((file) => `<li><a href="${file.href}">${file.name}</a></li>`)
.join('');
return `
<!doctype html>
<html>
<head><title>Directory listing</title></head>
<body>
<h1>Files</h1>
<ul>${directoryItems}${fileItems}</ul>
</body>
</html>
`;
},
};
AI Coding Instructions
- Set
formatexactly to'html'; other values do not satisfyListOptionsHtmlFormat. - Implement
renderusing theListRendersignature expected by the Fastify static integration. - Escape file names, paths, and other dynamic values before inserting them into generated HTML.
- Return complete, valid HTML when using this format so browsers can render the directory listing correctly.
- Use this interface when configuring HTML directory listings rather than JSON or plain-text listing formats.
Was this page helpful?