#!/bin/bash # Check API responses from running node 1. # Usage: npm run check-api set -e PORTFILE="/tmp/p2pds-node1.port" if [ ! -f "$PORTFILE" ]; then echo "Node 1 not running. Start with: npm run start:node1" exit 1 fi PORT=$(cat "$PORTFILE") BASE="http://localhost:$PORT" # Get auth token from the page HTML=$(curl -s "$BASE/") TOKEN=$(echo "$HTML" | grep -o '__P2PDS_TOKEN__="[^"]*"' | sed 's/__P2PDS_TOKEN__="//;s/"//') echo "=== Server ===" echo " URL: $BASE" echo " Token: ${TOKEN:0:16}..." echo "" echo "=== OAuth Status ===" curl -s "$BASE/oauth/status" | python3 -m json.tool echo "" echo "=== Overview (key fields) ===" curl -s -H "Authorization: Bearer $TOKEN" "$BASE/xrpc/org.p2pds.app.getOverview" | python3 -c " import json, sys d = json.load(sys.stdin) if 'error' in d: print(' ERROR:', d.get('error'), '-', d.get('message')) else: print(' did:', d.get('did')) print(' handle:', d.get('handle')) print(' replication.enabled:', d.get('replication', {}).get('enabled')) tracked = d.get('replication', {}).get('trackedDids', []) print(' trackedDids:', tracked) sources = d.get('replication', {}).get('didSources', {}) print(' didSources:', sources) print(' policies:', d.get('policy', {}).get('policyCount')) " echo "" echo "=== Page HTML markers ===" echo " Has TOKEN: $(echo "$HTML" | grep -c '__P2PDS_TOKEN__')" echo " Has p2p-app: $(echo "$HTML" | grep -c '')" echo " Has bundle: $(echo "$HTML" | grep -c 'app.js')" echo " Cache-Control: $(curl -sI "$BASE/" | grep -i cache-control || echo 'none')"