forked from upstream/filebrowser
+11



![coderabbitai[bot]](/avatar/4a08c485fbe908b864e4cf902fddaff20a4dd8a58faf8f65f051648bd2ef3153?size=40)




45a14bf2f2
Signed-off-by: MichaIng <micha@dietpi.com> Co-authored-by: Kevin B. <kurami32_kbm@proton.me> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Mattijs Bliek <mattijs@mattijsbliek.com> Co-authored-by: GammelSami <39372285+GammelSami@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: yzxcj797 <54314860+yzxcj797@users.noreply.github.com> Co-authored-by: yzxcj797 <yzxcj797@users.noreply.github.com> Co-authored-by: DireMunchkin <dire.munchkin@proton.me> Co-authored-by: Chris <39135018+Chri6s@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Aditya Raj Singh <github@adityaraj.com> Co-authored-by: tbsagdic <86909795+tbsagdic@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Ethan Lee Qi Yang <pluscompanyhqDEPT@gmail.com> Co-authored-by: Aditya Raj Singh <aditya@bncw.in> Co-authored-by: MichaIng <micha@dietpi.com> Co-authored-by: FandacqkaCorp <david@davidyloreto.com> Co-authored-by: FandacqkaCorp <275647464+FandacqkaCorp@users.noreply.github.com> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: connorjfarrell <connorjfarrell@users.noreply.github.com>
98 lines
2.5 KiB
Bash
Executable File
98 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
VITE_PORT="${VITE_DEV_PORT:-5173}"
|
|
VITE_ORIGIN="${VITE_DEV_ORIGIN:-http://localhost:8080}"
|
|
VITE_CLIENT_PORT="${VITE_DEV_CLIENT_PORT:-8080}"
|
|
READY_URL="http://127.0.0.1:${VITE_PORT}/__vite/@vite/client"
|
|
WAIT_SECONDS="${VITE_READY_TIMEOUT:-60}"
|
|
|
|
stop_listeners_on_port() {
|
|
local port=$1
|
|
if command -v fuser >/dev/null 2>&1; then
|
|
fuser -k "${port}/tcp" 2>/dev/null || true
|
|
elif command -v lsof >/dev/null 2>&1; then
|
|
local pids
|
|
pids="$(lsof -ti :"${port}" 2>/dev/null || true)"
|
|
if [[ -n "$pids" ]]; then
|
|
kill -TERM $pids 2>/dev/null || true
|
|
fi
|
|
elif command -v ss >/dev/null 2>&1; then
|
|
local pid
|
|
pid="$(ss -tlnp 2>/dev/null | sed -n "s/.*:${port} .*pid=\\([0-9]*\\).*/\\1/p" | head -n1)"
|
|
if [[ -n "$pid" ]]; then
|
|
kill -TERM "$pid" 2>/dev/null || true
|
|
fi
|
|
fi
|
|
sleep 0.3
|
|
}
|
|
|
|
cleanup() {
|
|
local status=$?
|
|
trap - EXIT INT TERM
|
|
if [[ -n "${AIR_PID:-}" ]] && kill -0 "$AIR_PID" 2>/dev/null; then
|
|
kill -TERM "$AIR_PID" 2>/dev/null || true
|
|
fi
|
|
if [[ -n "${VITE_PID:-}" ]] && kill -0 "$VITE_PID" 2>/dev/null; then
|
|
kill -TERM "$VITE_PID" 2>/dev/null || true
|
|
fi
|
|
if [[ -n "${AIR_PID:-}" ]]; then
|
|
wait "$AIR_PID" 2>/dev/null || true
|
|
fi
|
|
wait "$VITE_PID" 2>/dev/null || true
|
|
exit "$status"
|
|
}
|
|
|
|
wait_for_vite() {
|
|
local elapsed=0
|
|
while (( elapsed < WAIT_SECONDS )); do
|
|
if curl -fsS -o /dev/null "$READY_URL" 2>/dev/null; then
|
|
return 0
|
|
fi
|
|
if ! kill -0 "$VITE_PID" 2>/dev/null; then
|
|
echo "Vite dev server exited before becoming ready." >&2
|
|
return 1
|
|
fi
|
|
sleep 1
|
|
elapsed=$((elapsed + 1))
|
|
done
|
|
echo "Timed out waiting for Vite at ${READY_URL}" >&2
|
|
return 1
|
|
}
|
|
|
|
trap cleanup EXIT INT TERM
|
|
|
|
if curl -fsS -o /dev/null "$READY_URL" 2>/dev/null || ss -tln 2>/dev/null | grep -q ":${VITE_PORT} "; then
|
|
echo "Clearing stale listener on port ${VITE_PORT}..."
|
|
stop_listeners_on_port "$VITE_PORT"
|
|
fi
|
|
|
|
echo "Starting Vite dev server on 127.0.0.1:${VITE_PORT}..."
|
|
(
|
|
cd "$ROOT/frontend"
|
|
export VITE_DEV_ORIGIN="$VITE_ORIGIN"
|
|
export VITE_DEV_PORT="$VITE_PORT"
|
|
export VITE_DEV_CLIENT_PORT="$VITE_CLIENT_PORT"
|
|
exec npm run dev
|
|
) &
|
|
VITE_PID=$!
|
|
|
|
wait_for_vite
|
|
echo "Vite is ready. Starting Air..."
|
|
|
|
(
|
|
cd "$ROOT/backend"
|
|
export FILEBROWSER_DEVMODE=true
|
|
AIR_BIN="$(cd build && go tool -n air)"
|
|
exec "$AIR_BIN"
|
|
) &
|
|
AIR_PID=$!
|
|
|
|
# wait -n needs Bash 4.3+ (macOS /bin/bash is 3.2)
|
|
while kill -0 "$VITE_PID" 2>/dev/null && kill -0 "$AIR_PID" 2>/dev/null; do
|
|
sleep 1
|
|
done
|
|
echo "A dev process exited; stopping the other..." >&2
|
|
exit 1
|