$ show vercel/serve
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.
The LLM identified 2 files worth highlighting for reuse:
Exports a `resolve` function that wraps a promise and returns a tuple of `[error, data]` similar to Go's error handling pattern. This is a self-contained, generic utility that can be extracted and reused in any Node.js project to simplify async error handling without try-catch blocks. It also re-exports `promisify` from `node:util`.
Contains the `parseEndpoint` function which parses a string into a `ParsedEndpoint` object supporting TCP URLs, Unix domain sockets, Windows named pipes, and plain port numbers. This demonstrates a clean, extensible parsing pattern using `url.parse` and switch-case logic. It is reusable as a standalone parser for any CLI tool that needs to accept multiple endpoint formats.