1 unstable release
Uses new Rust 2024
new 0.1.0 | Apr 25, 2025 |
---|
#342 in HTTP server
16KB
155 lines
webserve
A blazing-fast static file and SPA Web server written in Rust, powered by warp
. Supports live reload, SPA fallback, and directory serving — like npm serve
, but compiled and production-ready.
🚀 Features
- ✅ Serve any directory (
-d ./dist
) - ✅ SPA fallback support (
--spa
) - ✅ File watching with automatic browser reload (
--watch
) - ✅ Configurable host and port (
-h
,-p
) - ✅ Built with Rust + Tokio for high performance
📦 Installation
git clone https://github.com/your-username/webserve
cd webserve
cargo build --release
The executable will be located in target/release/webserve
.
You can also install it globally (requires Rust):
cargo install --path .
🛠 Usage
webserve [OPTIONS]
Options
Flag | Description | Default |
---|---|---|
-d , --dir |
Directory to serve files from | Current directory |
-p , --port |
Port to listen on | 8080 |
-h , --host |
Host/IP to bind | 127.0.0.1 |
--spa |
Enable SPA fallback (404 → index.html) | disabled |
-w , --watch |
Enable file watching + auto-reload | disabled |
🧪 Example
Serve a Vite/React app from ./dist
, with SPA fallback and live reload:
webserve -d ./dist --spa --watch
💻 Injected Reload Script
When --watch
is used, index.html
is automatically injected with:
<script>
const socket = new WebSocket(`ws://${location.host}/reload`);
socket.onmessage = () => location.reload();
</script>
📁 Project Structure
webserve/
├── src/
│ └── main.rs # Web server logic
├── Cargo.toml # Dependencies
└── README.md
📜 License
MIT © Mark Wayne Menorca
Dependencies
~12–22MB
~309K SLoC