#!/usr/bin/env bash # scripts/check_token_server.sh # Uso: ./scripts/check_token_server.sh [ROOM] [USERNAME] # Ejemplo: ./scripts/check_token_server.sh https://avanzacast-servertokens.bfzqqk.easypanel.host myroom alice set -euo pipefail SERVER=${1:-} ROOM=${2:-test-room} USER=${3:-e2e-user} if [ -z "$SERVER" ]; then echo "Usage: $0 [ROOM] [USERNAME]" echo "Example: $0 https://localhost:4000 myroom alice" exit 2 fi SESSION_URL="$SERVER/api/session" echo "=== Token server diagnostics ===" echo "Server: $SERVER" echo "Session endpoint: $SESSION_URL" echo "\n--- OPTIONS (CORS preflight) ---" curl -i -X OPTIONS "$SESSION_URL" -H "Origin: http://localhost:5176" || true echo "\n--- POST /api/session (create) ---" HTTP=$(curl -s -w "%{http_code}" -o /tmp/curl_out.txt -X POST "$SESSION_URL" \ -H "Content-Type: application/json" \ -d "{ \"room\": \"$ROOM\", \"username\": \"$USER\" }" || true) echo "HTTP status: $HTTP" echo "Body:" cat /tmp/curl_out.txt || true # If creation returned id, try GET token if [ "$HTTP" -ge 200 ] && [ "$HTTP" -lt 400 ]; then BODY=$(cat /tmp/curl_out.txt) # Try to parse id or sessionId ID=$(echo "$BODY" | python3 -c "import sys, json; d=json.load(sys.stdin); print(d.get('id') or d.get('sessionId') or d.get('session_id') or '')" 2>/dev/null || true) echo "Parsed session id: '$ID'" if [ -n "$ID" ]; then TOKEN_URL="$SERVER/api/session/$ID/token" echo "\n--- GET $TOKEN_URL ---" curl -i "$TOKEN_URL" || true else echo "No session id found in create response; inspect body." fi else echo "Session creation failed (status $HTTP). Check backend logs and CORS." fi # Cleanup rm -f /tmp/curl_out.txt echo "\nDiagnostics complete. If you see 'Access-Control-Allow-Origin' missing or response status 0/0, likely CORS or network issue."