#!/bin/bash

# Run this script AFTER configuring Nginx Proxy Manager
# This updates the frontend to use the domain URL for API calls

set -e

echo "🔄 Updating frontend configuration to use domain..."

ssh root@37.60.249.71 << 'ENDSSH'
cd /opt/zerp

# Update docker-compose.yml to use domain
sed -i 's|NEXT_PUBLIC_API_URL:.*|NEXT_PUBLIC_API_URL: https://zerp.atmata-group.com/api/v1|' docker-compose.yml

# Rebuild frontend with new config
docker-compose stop frontend
docker-compose rm -f frontend
docker-compose up -d --build frontend

echo ""
echo "✅ Frontend updated to use domain URL!"
echo ""
echo "Test the system at: https://zerp.atmata-group.com/"
ENDSSH

echo "🎉 Update complete!"
