README
ยถ
glivereload
A fast and simple Go CLI tool that serves static files over HTTP with live reload capabilities. Perfect for web development, documentation sites, or any project where you need automatic browser refresh on file changes.
Features
- ๐ Fast HTTP server - Built with Go's efficient HTTP server
- ๐ Live reload - Automatically refreshes browsers when files change
- ๐ Directory serving - Serves static files and directory listings
- ๐ฏ Smart file watching - Recursively watches directories with intelligent filtering
- ๐ WebSocket-based - Real-time communication for instant reloads
- ๐ก๏ธ Security - Protection against directory traversal attacks
- ๐ฑ Cross-platform - Works on Windows, macOS, and Linux
- โก Zero configuration - Works out of the box
Installation
From Source
git clone https://codeberg.org/Pontoporeia/glivereload.git
cd glivereload
go build -o glivereload
Using Go Install
go install codeberg.org/Pontoporeia/glivereload@latest
Usage
Basic Usage
Serve the current directory on port 8080:
glivereload
Serve a specific directory:
glivereload serve /path/to/your/project
# or
glivereload --dir /path/to/your/project
Command Line Options
glivereload [flags]
glivereload serve [directory] [flags]
Flags:
-d, --dir string Directory to serve (default ".")
-h, --help Help for glivereload
-p, --port int Port to serve on (default 8080)
-v, --verbose Enable verbose logging
Examples
Serve on a different port:
glivereload --port 3000
Serve with verbose logging:
glivereload --verbose --dir ./dist
Serve a specific directory with custom port:
glivereload serve ./public --port 9000 --verbose
How It Works
- HTTP Server: Serves static files from the specified directory
- File Watcher: Monitors file changes recursively in the directory
- WebSocket Connection: Maintains real-time connection with browsers
- Live Reload Script: Automatically injected into HTML files
- Smart Filtering: Ignores temporary files, hidden files, and common build directories
File Watching
The tool automatically watches for changes in:
- All files in the served directory and subdirectories
- Creates, modifications, and deletions
It intelligently ignores:
- Hidden files and directories (starting with
.
) - Temporary files (
~
,.tmp
,.swp
, etc.) - Common build/dependency directories (
node_modules
,.git
,build
,dist
, etc.) - Binary files and executables
Browser Support
The live reload functionality works with all modern browsers that support WebSockets:
- Chrome/Chromium
- Firefox
- Safari
- Edge
Development
Prerequisites
- Go 1.21 or later
Dependencies
- cobra - CLI framework
- fsnotify - File system notifications
- gorilla/websocket - WebSocket implementation
Building
go mod tidy
go build -o glivereload
Testing
go test ./...
Features in Detail
HTML Injection
For HTML files, the live reload script is automatically injected before the
closing </body>
tag. The script:
- Establishes WebSocket connection to the server
- Listens for reload messages
- Automatically refreshes the page when files change
- Handles reconnection on server restart
Directory Listings
When accessing a directory without an index.html
file, a clean directory
listing is served with:
- Folder and file icons
- Clickable navigation
- Parent directory navigation
- Responsive design
Security
- Path traversal protection prevents access to files outside the served directory
- CORS headers allow connections from any origin (suitable for development)
- No execution of server-side code - purely static file serving
Use Cases
- Web Development: Instant preview of HTML, CSS, and JavaScript changes
- Documentation: Live preview of markdown or HTML documentation
- Static Sites: Development server for static site generators
- Prototyping: Quick setup for frontend prototypes
- Learning: Great for web development tutorials and learning
Troubleshooting
Port Already in Use
If the default port 8080 is busy, specify a different port:
glivereload --port 3000
Live Reload Not Working
- Check that JavaScript is enabled in your browser
- Ensure WebSocket connections aren't blocked by firewall
- Use
--verbose
flag to see detailed logs - Check browser console for WebSocket connection errors
File Changes Not Detected
- Verify the file is within the served directory
- Check if the file extension is being filtered
- Use
--verbose
to see which files are being watched - Some editors may use atomic writes - try saving differently
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
MIT License - see LICENSE file for details
Changelog
v1.0.0
- Initial release
- Basic HTTP server with static file serving
- Live reload functionality via WebSocket
- Recursive file watching
- CLI interface with cobra
- Directory listings
- Security protections
Documentation
ยถ
There is no documentation for this package.