$ show fastify/fastify-static
This repository contains @fastify/static, a Fastify plugin for efficiently serving static files. The plugin provides high-performance static file serving with features including MIME type detection, directory listing (JSON/HTML formats), pre-compressed file brokering (brotli/gzip/deflate), range requests, cache control headers, and robust path security to prevent directory traversal attacks. It follows Fastify plugin conventions and decorates reply objects with sendFile and download methods for flexible file serving. The architecture separates concerns with core logic in index.js, directory listing functionality in lib/dirList.js, and error definitions in lib/errors.js. Notable implementation details include concurrent file system operations using fastq for directory listings, sophisticated path normalization and security checks to handle various edge cases (non-canonical paths, dot-dot segments, symbolic links), and intelligent content negotiation for serving the optimal pre-compressed file variant based on client Accept-Encoding headers.
The LLM identified 1 files worth highlighting for reuse:
Implements efficient directory listing with concurrent file system operations using fastq for performance. Supports both JSON and HTML output formats with custom rendering functions, recursive directory information gathering (file counts, sizes, modification times), and robust path security to prevent directory traversal. The module is self-contained with minimal dependencies (only node built-ins and fastq) and could be extracted for use in other projects needing similar directory listing functionality.