A minimalist static file server for Go with automatic browser reloading via WebSockets.
- Live Reload: Automatically refreshes the browser when files are saved.
- Script Injection: Injects the WebSocket client into HTML files on the fly.
- Recursive Watcher: Monitors the current directory and all subdirectories.
- Debounced Events: Prevents multiple rapid refreshes.
- Install dependencies:
go mod tidy
- Run the server:
go run main.go
- Open your browser:
Navigate to
http://localhost:9797
go build -o goserver main.go- The server watches for
WriteorCreateevents usingfsnotify. - It serves static files and injects a small
<script>before the</body>tag in HTML files. - When a file change is detected, a signal is sent via WebSockets to all connected clients to trigger
window.location.reload().