shelf_packages_handler
3.0.2, released 4 years ago by tools.dart.dev
Shelf handler that serves a `packages/` directory of Dart package assets.
Quiet but busy
What it does
Provides a Shelf handler that resolves `package:` URIs and serves the corresponding files from a `packages/` directory. Designed to be placed first in a Cascade so other requests fall through to subsequent handlers.
AI-written summary of version 3.0.2, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to serve Dart package assets over HTTP during development
- You are building a simple Shelf server and want automatic package resolution
- You want a drop‑in handler that works with Shelf's Cascade
Skip it when
- You require a full‑featured static file server with caching and compression
- You need to serve assets from locations other than `packages/`
- You are deploying to production where a CDN is preferred
Strengths
- Very small and focused API
- Integrates directly with Shelf's Cascade
- Null‑safe and requires only core Shelf dependencies
Weaknesses
- Only serves `packages/` paths, no other static file features
- No built‑in caching or performance optimizations
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 3
import 'package:shelf/shelf.dart';
import 'package:shelf_packages_handler/shelf_packages_handler.dart';
final handler = packagesHandler({
'my_package': Uri.parse('file:///path/to/my_package/lib/'),
});
final cascade = Cascade().add(handler).add(_otherHandler).handler;
Works with
Packages commonly used together with shelf_packages_handler: ones it builds on, ones built on it, and its own family.
- shelfshelf_packages_handler depends on itComposable web server middleware for Dart
- shelf_staticshelf_packages_handler depends on itServe static files over HTTP with the shelf package
- shelf_web_socketSame familyShelf handler that upgrades HTTP to WebSocket and provides a WebSocketChannel per connection.
- shelf_proxySame familyA shelf handler for proxying HTTP requests to another server.
- sseSame familyBidirectional Server Sent Events client and server for Dart.
- ddsSame familyLibrary to spawn and communicate with the Dart Developer Service (DDS) via HTTP, WebSocket, or SSE.
- dwdsSame familyProxies between the Chrome debug protocol and the Dart VM service protocol.
- build_runnerSame familyA build system for Dart code generation and modular compilation.