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.
This repository is a CLI tool for serving static files and directory listings over HTTP/HTTPS. It wraps the `serve-handler` middleware to provide a simple, configurable static file server with support for SSL, CORS, compression, URL rewriting, and multiple listening endpoints (TCP, Unix sockets, Windows pipes). The architecture is a single Node.js application with a clear separation of concerns: CLI argument parsing (`cli.ts`), configuration loading with JSON schema validation (`config.ts`), server creation with HTTP/HTTPS support (`server.ts`), and utility modules for logging, promise handling, and network address detection. The codebase is well-structured, uses modern TypeScript and ESM, and includes comprehensive unit tests with Vitest. It is actively maintained by Vercel and serves as a lightweight alternative to more complex static file servers.