# 🚨 Quick Fix for CORS Error

## Problem
Website `https://muaziin.sa` is blocked by CORS when trying to access `https://muaziin.sa`

## Root Cause
The backend server at `api.muaziin.sa` is returning:
```
Access-Control-Allow-Origin: http://localhost:5173
```

Instead of:
```
Access-Control-Allow-Origin: https://muaziin.sa
```

## Solution: 3 Steps

### Step 1: Update `.env` file on production server

```bash
# SSH into your server
ssh user@your-server

# Navigate to backend directory
cd /path/to/muzan/backend

# Edit .env file
nano .env
```

Add or update this line (IMPORTANT: No spaces between domains):
```env
CORS_ORIGIN=https://muaziin.sa,https://www.muaziin.sa,https://muaziin.sa
```

Save and exit (Ctrl+X, then Y, then Enter)

### Step 2: Upload latest code

```bash
# Option A: Using Git (recommended)
cd /path/to/muzan
git pull origin main

# Option B: Upload files manually via FTP/SCP
# Upload: backend/src/config.js
# Upload: backend/src/app.js
```

### Step 3: Restart the server

```bash
# If using PM2:
pm2 restart muzan-backend
pm2 logs muzan-backend

# If using Passenger/cPanel:
touch tmp/restart.txt

# If using systemd:
sudo systemctl restart muzan-backend
```

## Verification

1. Open `https://muaziin.sa` in your browser
2. Open Developer Console (F12)
3. Go to Network tab
4. Reload the page
5. Check API calls - should show status 200, not CORS errors

## Expected Console Output

After restart, the backend server should log:
```
🔐 CORS Origins configured: [
  'https://muaziin.sa',
  'https://www.muaziin.sa',
  'https://muaziin.sa'
]
```

If you see this, the fix is working!

## Still not working?

Run this test script:
```bash
cd /path/to/muzan/backend
chmod +x test-cors.sh
./test-cors.sh
```

Or manually test:
```bash
curl -I -H "Origin: https://muaziin.sa" https://muaziin.sa/api/public/contact
```

Look for:
```
Access-Control-Allow-Origin: https://muaziin.sa
```

---

**Need help?** Check `DEPLOYMENT.md` for detailed troubleshooting.
