BASH
Quick Local HTTP Server for Static Files
Launch a temporary local HTTP server using Python's http.server module to serve static files from your current directory, perfect for front-end development.
#!/bin/bash
PORT=${1:-8000}
echo "Starting local server on http://localhost:$PORT"
echo "Serving files from: $(pwd)"
# Python 3: http.server
# Python 2: SimpleHTTPServer
if command -v python3 &>/dev/null; then
python3 -m http.server $PORT
elif command -v python &>/dev/null; then
python -m SimpleHTTPServer $PORT
else
echo "Error: Python not found. Please install Python to run a local server."
exit 1
fi
How it works: This script quickly launches a local HTTP server using Python. It defaults to port 8000 but can be configured with an argument. It checks for `python3` first, then falls back to `python` (for Python 2 environments), allowing developers to serve static files from the current directory, which is invaluable for front-end testing and prototyping without needing to configure a full web server.