Overview
Thekosh serve command starts a local HTTP server to preview your site. In development mode (--dev), it builds the site, watches for changes, and automatically reloads the browser.
Usage
Flags
Enable development mode with build, watch, and live reload. This mode:
- Builds the site on startup
- Watches for file changes and rebuilds automatically
- Skips PWA generation for faster builds
- Auto-detects
baseURLashttp://localhost:2604if empty in config - Enables Server-Sent Events for browser auto-reload
Host or IP address to bind the server to.Use
0.0.0.0 to make the server accessible on your local network:Port number to listen on.
Include draft posts in development mode. Posts with
draft: true in frontmatter are normally excluded.Override base URL from config. In dev mode with empty
baseURL, this is auto-detected as http://localhost:2604.Examples
Development Mode
When using--dev, the server provides:
Live Reload
- Browser connects to
/eventsendpoint for Server-Sent Events - File changes trigger automatic page reload
- No browser extensions required
File Watching
Monitors these paths for changes:content/- Markdown files- Template directory (default:
themes/<theme>/templates/) - Static directory (default:
themes/<theme>/static/) kosh.yaml- Configuration file
Fast Rebuilds
- Incremental builds process only changed files
- Cache rehydration for template-only changes
- Debounced rebuilds (500ms delay) to batch rapid changes
Auto baseURL Detection
IfbaseURL is empty in kosh.yaml, dev mode auto-detects it:
Caching Behavior
The server applies different cache headers based on file type:Hashed Assets (Immutable)
Files with content hashes (e.g.,style-a1b2c3d4.css):
HTML Pages (No Cache)
HTML files and directory indexes:Other Static Files
Images, fonts, etc.:Terminal Output
404 Handling
When a page is not found, the server:- Returns HTTP 404 status
- Serves
public/404.htmlif it exists - Falls back to plain text β404 - Page Not Foundβ
Security Features
Path Validation
All requested paths are validated to prevent directory traversal attacks:MIME Types
Proper MIME types are set, including:.wasmβapplication/wasm.cssβtext/css.jsβapplication/javascript
Graceful Shutdown
The server supports graceful shutdown via:SIGINT(Ctrl+C)SIGTERM
- Stop accepting new connections
- Finish processing active requests (5-second timeout)
- Stop file watcher
- Clean up resources
Troubleshooting
Port Already in Use
Changes Not Reloading
- Check browser console for
/eventsconnection - Verify watched paths include changed file
- Clear browser cache or use incognito mode
Assets Not Loading
Ensure the build completed before serving:Related Commands
kosh build- Build the site without servingkosh clean- Clean output before serving