# Jadwa AI Flask App - Setup Complete

## Summary

The "Index of /" issue has been fixed and the Flask app is now properly configured with automated monitoring.

## What Was Fixed

### 1. Nginx Configuration
- **Problem**: nginx was serving static files instead of proxying to Flask app
- **Solution**: Created `/etc/nginx/conf.d/00-jadwaai.com.conf` to proxy requests to port 5006

### 2. GeoIP Restriction
- **Problem**: App was blocking all non-Saudi IPs (403 error)
- **Solution**: Disabled `saudi_only_access` setting in database

## Monitoring Scripts Created

| Script | Purpose | Location |
|--------|---------|----------|
| `monitor_app.sh` | Checks app status and restarts if needed (runs every 15 min) | `scripts/monitor_app.sh` |
| `start_app.sh` | Manually start the Flask app with proper configuration | `scripts/start_app.sh` |
| `health_check.sh` | Quick health check that returns exit code | `scripts/health_check.sh` |
| `status.sh` | Display current app status | `scripts/status.sh` |

## Cron Job

```bash
*/15 * * * * /home/ashraffarid2010/jadwaai.com/scripts/monitor_app.sh >/dev/null 2>&1
```

The monitoring script runs every 15 minutes and will:
1. Check if gunicorn process is running
2. Test if app responds with HTTP 200
3. Restart the app automatically if either check fails

## How to Use

### Check Status
```bash
/home/ashraffarid2010/jadwaai.com/scripts/status.sh
```

### Manual Restart
```bash
/home/ashraffarid2010/jadwaai.com/scripts/start_app.sh
```

### View Logs
```bash
# Monitoring log
tail -f /home/ashraffarid2010/jadwaai.com/logs/monitor.log

# Gunicorn log
tail -f /home/ashraffarid2010/jadwaai.com/logs/gunicorn.log
```

## Current Status

- ✅ Flask app running on port 5006
- ✅ Nginx proxying requests correctly
- ✅ Domain `jadwaai.com` accessible (HTTP 200)
- ✅ Monitoring active (every 15 minutes)
- ✅ GeoIP restriction disabled

## App Details

- **Port**: 5006
- **Process**: gunicorn (4 workers)
- **User**: pakchoi
- **App Directory**: `/home/ashraffarid2010/jadwaai.com`
- **Logs Directory**: `/home/ashraffarid2010/jadwaai.com/logs`

## Notes

- The app is set to auto-restart on failure every 15 minutes
- Logs are kept in `logs/` directory
- GeoIP restriction can be re-enabled via SystemSetting if needed
