zkt25/sk1/not use/fix-react-config.sh

45 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Create a temporary pod to examine the frontend code
kubectl run debug-react -n sk1 --image=busybox -- sleep 3600
# Wait for pod to be ready
kubectl wait --for=condition=Ready pod/debug-react -n sk1 --timeout=60s
# Create a config.js file with the correct API URL
cat > /tmp/config.js << EOF
// API Configuration
window.API_URL = '/api'; // Use relative path for API calls
console.log('API configuration loaded');
EOF
# Copy this file to the frontend pod's HTML directory
kubectl cp /tmp/config.js debug-react:/tmp/config.js -n sk1
# Find all frontend pods
FRONTEND_PODS=$(kubectl get pods -n sk1 -l app=frontend -o jsonpath='{.items[*].metadata.name}')
# Copy the config to each frontend pod
for pod in $FRONTEND_PODS; do
echo "Updating config in pod $pod..."
kubectl cp /tmp/config.js $pod:/usr/share/nginx/html/config.js -n sk1
# Verify the file was copied
kubectl exec $pod -n sk1 -- ls -la /usr/share/nginx/html/config.js || echo "Failed to copy config.js to $pod"
done
# Update index.html to include this config file
for pod in $FRONTEND_PODS; do
kubectl exec $pod -n sk1 -- sh -c '
if grep -q config.js /usr/share/nginx/html/index.html; then
echo "Config already included in index.html"
else
echo "Adding config.js to index.html"
sed -i "s|<head>|<head>\n <script src=\"/config.js\"></script>|" /usr/share/nginx/html/index.html
fi
'
done
echo "✅ Frontend configuration updated with correct API URL"
echo "Try accessing your application again at https://nudges.works"