#!/usr/bin/env bash # serve-web.sh — start (or restart) the static file server on the VPS. # Runs `npx serve` in the background, logs to ~/waste-www.log. # # SETUP: copy this file to serve-web.sh (gitignored) and set HOST below. # # Usage: # ./serve-web.sh # # Optional env vars: # HOST SSH target (user@host) (required — edit below) # REMOTE_DIR path on VPS (default: ~/waste-www) # PORT local port on VPS (default: 1337) set -euo pipefail HOST="${HOST:-user@YOUR_VPS_IP}" # ← edit this REMOTE_DIR="${REMOTE_DIR:-~/waste-www}" REMOTE_LOG="~/waste-www.log" REMOTE_PID="~/waste-www.pid" PORT="${PORT:-1337}" if [[ "$HOST" == *YOUR_VPS_IP* ]]; then echo "error: edit HOST in this script (or export HOST=user@your-vps before running)" >&2 exit 1 fi ssh "$HOST" bash </dev/null || true rm -f $REMOTE_PID fi echo "[\$(date)] starting npx serve on port $PORT" >> $REMOTE_LOG nohup npx serve -s $REMOTE_DIR -l $PORT >> $REMOTE_LOG 2>&1 & echo \$! > $REMOTE_PID echo "→ started (pid \$(cat $REMOTE_PID)), logging to $REMOTE_LOG" EOF