Static Routes Overview
Serve pre-built assets (HTML, CSS, JS, images, docs) directly from disk without writing explicit route handlers. Static hosting is ideal for:
- Landing / status pages
- Documentation bundles
- Front‑end single page apps (with additional routing rules)
- Images and downloadable assets
The static files service mounts a directory tree at a request path prefix. Requests under that prefix are mapped to files relative to the configured root path.
Chapters
| Order | Chapter | Focus |
|---|---|---|
| 1 | Serving Static Files | Basic static file service (Add-KrStaticFilesService) |
| 2 | File Server & Directory Browsing | Whole-site directory hosting + listings (Add-KrFileServer) |
| 3 | Static Route Overrides | Dynamic endpoints under a static prefix (Add-KrMapRoute) |
| 4 | Adding a Favicon | Register favicon middleware (Add-KrFavicon) |
| 5 | File Server Caching Headers | Global cache headers for static files (Add-KrFileServerMiddleware) |
| 6 | Response Caching & Conditional Requests | Dynamic validators + in-memory cache (Add-KrCacheMiddleware) |
Upcoming chapters (planned): SPA / fallback routing; multiple static roots & versioned assets.
Quick Start
From the repository root run the sample script:
pwsh .\examples\PowerShell\Tutorial\6-Static-Routes.ps1
Then browse (default listener http://127.0.0.1:5000):
Stop the server with Ctrl+C.
Key Cmdlets
Initialize-KrRoot— lock working root so relative asset paths resolve reliably.Add-KrStaticFilesService— register a static file mount (-RequestPath+-RootPath).Add-KrEndpoint/New-KrServer/Enable-KrConfiguration/Start-KrServer— standard server lifecycle.
Next
Start with: Serving Static Files → File Server → Static Route Overrides. Then continue to Variable Routes to handle dynamic segments.
Contributions welcome — open issues or PRs in the repository.