A lightweight, simple HTTP server written in C for quickly serving static files.
Designed for:
- spinning up a quick local server
- demoing basic web development to your friends who ask questions
- whenever you have a .html file and need to spin up a quick server
- basic testing
- Serve files from any directory
- Runs on
localhost - Multithreaded (handles multiple requests)
- Optional live reload
- Basic HTTP support (GET only)
- MIME type detection
- Directory listing (if no
index.html) - Basic path safety protections
- Clean request logging
Add to it, or don't. That's up to you
Make sure you have gcc installed.
makeThis will produce:
./spigot./spigotServe current directory on default port 8080
./spigot <directory>Serve a specific directory:
./spigot public./spigot <port>Serve current directory on custom port:
./spigot 3000./spigot <directory> <port>Serve directory on custom port:
./spigot public 3000chmod +x spigot
sudo install -m 755 spigot /usr/local/bin/spigotOr add an alias (use your shell's config file (.bashrc, .zshrc, etc.))
echo 'alias serve="spigot"' >> ~/.zshrc
source ~/.zshrcEnable automatic browser refresh when files change:
./spigot --reloador:
./spigot public 3000 --reload- Server scans for file changes
- Injects a small script into HTML pages
- Browser polls server for updates
- Page reloads automatically when changes are detected
- If a directory contains
index.html→ it is served - Otherwise → a basic file listing is generated
Basic protections included:
- Blocks
..(directory traversal) - Sanitizes request paths
- Basic url decoding
- No HTTPS
- No authentication
- No advanced request validation
.html→text/html.css→text/css.js→application/javascript.png→image/png.jpg/.jpeg→image/jpeg- default →
application/octet-stream
Serving directory: .
URL: http://localhost:8080
Request logs:
[GET] /index.html → 200
[GET] /style.css → 200
[GET] /missing.txt → 404
This project is intentionally:
- simple
- readable
- hackable
It is not meant to replace full web servers, but to:
- prototype quickly
- serve as a quick convenience tool
- minor testing
- GET requests only
- No HTTP/2
- No persistent connections
- Thread-per-request model (not scalable)
- Live reload uses polling (not websockets)
Use it, modify it, break it, learn from it. That's the entire point.
Because sometimes you just want:
./spigot