glivereload

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2025 License: MIT Imports: 13 Imported by: 0

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

  1. HTTP Server: Serves static files from the specified directory
  2. File Watcher: Monitors file changes recursively in the directory
  3. WebSocket Connection: Maintains real-time connection with browsers
  4. Live Reload Script: Automatically injected into HTML files
  5. 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
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
  1. Check that JavaScript is enabled in your browser
  2. Ensure WebSocket connections aren't blocked by firewall
  3. Use --verbose flag to see detailed logs
  4. Check browser console for WebSocket connection errors
File Changes Not Detected
  1. Verify the file is within the served directory
  2. Check if the file extension is being filtered
  3. Use --verbose to see which files are being watched
  4. Some editors may use atomic writes - try saving differently

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. 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 ยถ

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL