72 lines
2.1 KiB
Bash
Executable File
72 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
OUT_DIR=".deploy_out"
|
|
mkdir -p "$OUT_DIR"
|
|
TS=$(date +%s)
|
|
OUT="${OUT_DIR}/cors_check_${TS}.log"
|
|
|
|
echo "Starting CORS check - output -> $OUT"
|
|
exec &> >(tee "$OUT")
|
|
|
|
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
|
cd "$BASE_DIR/packages/backend-api"
|
|
|
|
# stop previous backend if recorded
|
|
if [ -f /tmp/backend_api_pid.txt ]; then
|
|
PID=$(cat /tmp/backend_api_pid.txt) || true
|
|
if [ -n "$PID" ] && ps -p "$PID" > /dev/null 2>&1; then
|
|
echo "Stopping previous backend (pid=$PID)"
|
|
kill "$PID" || kill -9 "$PID" || true
|
|
sleep 1
|
|
fi
|
|
rm -f /tmp/backend_api_pid.txt
|
|
fi
|
|
|
|
# move old logs
|
|
[ -f /tmp/backend_api_run.log ] && mv /tmp/backend_api_run.log /tmp/backend_api_run.log.bak || true
|
|
|
|
# source .env.production if exists (do not leak secrets)
|
|
if [ -f ./.env.production ]; then
|
|
echo "Sourcing ./.env.production"
|
|
set -a
|
|
# shellcheck disable=SC1090
|
|
. ./.env.production
|
|
set +a
|
|
else
|
|
echo "No ./.env.production found in packages/backend-api — ensure env vars are set if needed"
|
|
fi
|
|
|
|
# Start backend with ALLOW_ALL_CORS=1 for debugging (background)
|
|
echo "Starting backend with ALLOW_ALL_CORS=1 (debug mode)"
|
|
nohup env ALLOW_ALL_CORS=1 npx tsx src/index.ts > /tmp/backend_api_run.log 2>&1 &
|
|
echo $! > /tmp/backend_api_pid.txt
|
|
sleep 2
|
|
|
|
echo "--- /tmp/backend_api_run.log (head) ---"
|
|
head -n 200 /tmp/backend_api_run.log || true
|
|
|
|
BROADCAST_ORIGIN="https://avanzacast-broadcastpanel.bfzqqk.easypanel.host"
|
|
TOKEN_URL="http://localhost:4000/api/token?room=studio-demo&username=simulator"
|
|
|
|
echo "--- Curl test against $TOKEN_URL with Origin: $BROADCAST_ORIGIN ---"
|
|
curl -i -s -H "Origin: $BROADCAST_ORIGIN" "$TOKEN_URL" | sed -n '1,200p' || true
|
|
|
|
echo "\n--- backend log (tail) ---"
|
|
tail -n 200 /tmp/backend_api_run.log || true
|
|
|
|
# show PID info
|
|
if [ -f /tmp/backend_api_pid.txt ]; then
|
|
echo "Backend PID: $(cat /tmp/backend_api_pid.txt)"
|
|
ps -p $(cat /tmp/backend_api_pid.txt) -o pid,ppid,cmd || true
|
|
fi
|
|
|
|
# show listening sockets
|
|
echo "\n--- Listening sockets for :4000 ---"
|
|
ss -ltnp | rg 4000 || true
|
|
|
|
cat "$OUT"
|
|
|
|
echo "CORS check finished. Log saved at $OUT"
|
|
|