My usual go-to for a quick static server is:
python -m http.server
But variations exist for a lot of languages. Php has one built-in too
python -m http.server
But variations exist for a lot of languages. Php has one built-in too
#!/usr/bin/env bash
set -e; [[ $TRACE ]] && set -x
port=8080
dir="."
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "usage: http-server [PORT] [DIRECTORY]"
echo " PORT Port to listen on (default: 8080)"
echo " DIRECTORY Directory to serve (default: .)"
exit 0
fi
if [ -n "$1" ]; then
port=$1
fi
if [[ -n "$2" ]]; then
dir=$2
fi
python3 -m http.server --directory "$dir" --protocol HTTP/1.1 "$port"That whole script could just be the last line! Maybe you could add defaults like
"${port:-8080}" port="${1:-8080}"
dir="${2:-.}" python3 -m http.server "${$1:-8080}" "${$2:-.}" #!/bin/bash
while :; do nc -l 80 < index.html; doneHTTP/0.9 web browser sends:
GET /
Netcat sends: <!doctype html>
...
Nowadays a browser will send `GET / HTTP/1.1` and then a bunch of headers, which a true HTTP/0.9 server may be able to filter out and ignore, but of course this script will just send the document and the browser will still assume it's a legacy server.(I'm sure if I dug in the http.server documentation I could find all those options too.)