chore: add playground serve script
This commit is contained in:
parent
2c2c9f769d
commit
843f80c54a
1 changed files with 18 additions and 0 deletions
18
playground/serve.sh
Executable file
18
playground/serve.sh
Executable file
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Serve the NISPS playground, finding an open port if needed.
|
||||||
|
|
||||||
|
PORT="${1:-8000}"
|
||||||
|
MAX_ATTEMPTS=20
|
||||||
|
DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
|
||||||
|
for ((i = 0; i < MAX_ATTEMPTS; i++)); do
|
||||||
|
candidate=$((PORT + i))
|
||||||
|
if ! ss -tlnp 2>/dev/null | grep -q ":${candidate} "; then
|
||||||
|
echo "Serving playground at http://localhost:${candidate}"
|
||||||
|
exec python3 -m http.server "$candidate" -d "$DIR"
|
||||||
|
fi
|
||||||
|
echo "Port ${candidate} in use, trying next..."
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "No open port found in range ${PORT}–$((PORT + MAX_ATTEMPTS - 1))" >&2
|
||||||
|
exit 1
|
||||||
Loading…
Reference in a new issue