$ account fastify
Fastify is a high-performance Node.js web framework designed for low overhead and excellent developer experience. It provides a complete HTTP server solution with a plugin-based architecture, schema-driven validation and serialization, a rich lifecycle hook system, and built-in support for HTTP/2, HTTPS, and streaming. The framework is built around a core instance factory (`fastify.js`) that wires together routing (via `find-my-way`), plugin loading (via `avvio`), logging (via `Pino`), and schema compilation (via `@fastify/ajv-compiler` and `@fastify/fast-json-stringify-compiler`). Key entry points include the `fastify()` factory, route shorthand methods (`.get`, `.post`, etc.), `register()` for plugins, and lifecycle hooks (`addHook`). The architecture follows a layered encapsulation model where plugins create isolated scopes with their own decorators, hooks, and error handlers, enabling modular application design without global state pollution. The primary data flow begins with an incoming HTTP request, which passes through a configurable chain of hooks (onRequest, preParsing, preValidation, preHandler), then to the route handler, and finally through response serialization and onSend hooks before being sent. Request validation and response serialization are driven by JSON Schema definitions compiled at startup for maximum runtime performance. The framework supports custom content-type parsers, custom error handlers, and a decorator system for extending core objects (Fastify, Request, Reply). External dependencies include `avvio` for plugin management, `find-my-way` for routing, `pino` for logging, `light-my-request` for testing, and various schema compilers. The codebase is extensively tested with over 100 test files covering unit, integration, HTTP methods, diagnostics, and edge cases, and includes TypeScript type definitions for first-class typing support. Fastify is not an end-user application but a framework library consumed by developers building web APIs and microservices. Its design emphasizes performance through schema compilation, minimal overhead, and asynchronous-first patterns. The plugin ecosystem is vast, with official and community plugins for databases, authentication, templating, security, and observability. The repository itself is under active development (version 6.0.0-alpha.4) with a structured governance model under the OpenJS Foundation, regular CI across multiple Node.js versions and package managers, and a clear LTS policy.
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 is the official Fastify CORS plugin, implementing Cross-Origin Resource Sharing (CORS) for Fastify servers. It provides comprehensive configuration for all standard CORS headers, including origin (string, regex, array, boolean, or dynamic function), methods, allowed headers, exposed headers, credentials, max age, cache control, and preflight handling. The architecture is a standard Fastify plugin that registers a configurable lifecycle hook (default onRequest) and a wildcard OPTIONS route to handle preflight requests. It supports dynamic configuration via a delegator callback or promise, and per-route CORS overrides via route config. The code is well-structured, thoroughly tested, and includes a particularly well-crafted `vary.js` module for managing the Vary header with caching. Dependencies are minimal and up to date.
@fastify/cookie is a Fastify plugin that adds cookie handling capabilities to Fastify applications. It provides automatic parsing of incoming cookies via Fastify hooks and methods to set, clear, and sign cookies on responses. The plugin integrates with Fastify's lifecycle through decorators and hooks, supporting various hook points for cookie parsing (onRequest, preParsing, etc.). It includes robust security features like cookie signing with HMAC, key rotation support, and protection against timing attacks. The implementation follows Fastify plugin best practices and provides both high-level convenience methods and low-level utilities for direct use.