GitHunt
LM

LMLK-seal/Web-Development-Server

A lightweight, professional-grade development server with live file watching and hot reload notifications for modern web applications.

๐Ÿš€ Professional Web Development Server

A lightweight, feature-rich development server designed for modern web applications with automatic live reload, anti-caching headers, and SPA (Single Page Application) routing support.

โœจ Features

  • ๐Ÿ”„ Live Reload - Automatic browser refresh when files change
  • ๐Ÿšซ Anti-Caching - Prevents browser caching during development
  • ๐ŸŽฏ SPA Support - Handles client-side routing for single-page applications
  • โšก Fast & Lightweight - Minimal overhead with efficient file watching
  • ๐ŸŽ›๏ธ Configurable - Customizable host, port, and directory settings
  • ๐Ÿ“ Smart Directory Detection - Automatically detects dist and build folders
  • ๐Ÿ”ง Professional Logging - Clean, informative console output

๐Ÿ“‹ Requirements

  • Python 3.6+
  • Required packages (install via pip install -r requirements.txt):
    • watchdog - File system monitoring
    • websockets - WebSocket support for live reload

๐Ÿš€ Quick Start

  1. Install dependencies:

    pip install -r requirements.txt
  2. Run the server:

    python Server.py
  3. Or specify a custom directory:

    python Server.py /path/to/your/project/dist

๐ŸŽ›๏ธ Usage

Basic Usage

# Serve current directory on default port (3000)
python Server.py

# Serve specific directory
python Server.py ./dist

# Custom port
python Server.py --port 8080

# Custom host
python Server.py --host 0.0.0.0

# Combined options
python Server.py ./build --port 8080 --host 0.0.0.0

Command Line Options

Option Short Default Description
directory - Current directory Directory to serve
--port -p 3000 HTTP server port
--host -H localhost Server host address

๐Ÿ—๏ธ Project Structure

This server is designed to work with modern web application builds:

your-project/
โ”œโ”€โ”€ dist/                 # Built application files
โ”‚   โ”œโ”€โ”€ index.html       # Main HTML file
โ”‚   โ”œโ”€โ”€ assets/          # Static assets
โ”‚   โ”‚   โ”œโ”€โ”€ main.js      # JavaScript bundles
โ”‚   โ”‚   โ”œโ”€โ”€ style.css    # Stylesheets
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ Server.py            # This development server
โ”œโ”€โ”€ requirements.txt     # Python dependencies
โ””โ”€โ”€ ...

โš™๏ธ How It Works

๐Ÿ”„ Live Reload System

  • File Watcher: Monitors your project directory for changes
  • WebSocket Connection: Establishes real-time communication with the browser
  • Debounced Updates: Prevents excessive reloads with 300ms delay
  • Smart Filtering: Ignores Python files and directories

๐Ÿšซ Anti-Caching Headers

The server automatically adds these headers to prevent browser caching:

Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Expires: 0

๐ŸŽฏ SPA Routing Support

  • Serves index.html for all non-existent routes
  • Perfect for React Router, Vue Router, Angular Router, etc.
  • Maintains clean URLs without hash routing

๐Ÿ”ง Configuration

Default Ports

  • HTTP Server: 3000
  • WebSocket Server: 3001

Environment Detection

The server provides helpful warnings if:

  • index.html is not found in the target directory
  • You're not running from a dist or build folder

๐Ÿ“Š Server Output

When running, you'll see a professional dashboard:

==================================================
  ๐Ÿš€ Professional Development Server is Running ๐Ÿš€
  - HTTP Server: http://localhost:3000
  - Live Reload:  Enabled
  - Caching:      Disabled

  Watching for file changes...
  Press Ctrl+C to stop.
==================================================

๐Ÿ› ๏ธ Development

Dependencies

Download the requirements.txt file.

Extending the Server

The server is built with modularity in mind:

  • DebouncedReloadHandler: Custom file system event handler
  • SPAEnabledHandler: HTTP request handler with SPA support
  • WebSocket server for live reload communication

๐Ÿšจ Troubleshooting

Common Issues

Port already in use:

python Server.py --port 8080

Permission denied:

# Use a port > 1024 for non-root users
python Server.py --port 3000

Live reload not working:

  • Check that WebSocket port (3001) is not blocked
  • Ensure your browser supports WebSocket connections
  • Verify that the index.html file contains the </body> tag for script injection
  • When still having cache issues try browser-Side Manual Fix: Forcing your browser to ignore its cache for a single request.
    On Windows/Linux: Ctrl + Shift + R or Ctrl + F5
    On Mac: Cmd + Shift + R

Browser Compatibility

The live reload feature requires WebSocket support:

  • โœ… Chrome 16+
  • โœ… Firefox 11+
  • โœ… Safari 7+
  • โœ… Edge 12+

๐Ÿ“ License

This project is open source and available under the MIT License.

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


Made with โค๏ธ for modern web development