# Testing the Dual-Mode Configuration

## Quick Test in Development Mode

### 1. Start Flask in Development Mode

**Option A - Using PowerShell (Easiest):**
```powershell
.\run_dev.ps1
```

**Option B - Using Command Prompt:**
```cmd
run_dev.bat
```

**Option C - Manual:**
```powershell
set FLASK_MODE=development
python app.py
```

### 2. What You Should See

Look for this in the console output:
```
[CONFIG] Running in DEVELOPMENT mode → localhost:5000
Server URL: http://localhost:5000
Mode: DEVELOPMENT
```

### 3. Test the Application

Open your browser and go to:
```
http://localhost:5000
```

You should see:
- ✅ Login page
- ✅ Google OAuth redirect works
- ✅ Dashboard loads after login

---

## Testing Production Mode (If Domain is Ready)

### 1. Prerequisites

Before testing production, you need:
- ✅ DNS configured: `sales.globalerc.pt` pointing to your server IP
- ✅ Reverse proxy running (nginx/Apache) on the same server
- ✅ SSL certificate installed
- ✅ Google Cloud Console updated with OAuth redirect URI: `https://sales.globalerc.pt/oauth2callback`

### 2. Start Flask in Production Mode

```powershell
.\run_prod.ps1
```

Flask output should show:
```
[CONFIG] Running in PRODUCTION mode → sales.globalerc.pt
Server URL: https://sales.globalerc.pt
Mode: PRODUCTION
```

### 3. Test Through Reverse Proxy

Once nginx/Apache is configured, visit:
```
https://sales.globalerc.pt
```

---

## Verification Checklist

### ✅ Development Mode Tests

- [ ] Flask starts without errors
- [ ] Console shows: `[CONFIG] Running in DEVELOPMENT mode → localhost:5000`
- [ ] Can access `http://localhost:5000` in browser
- [ ] Login page displays
- [ ] Google OAuth works (redirects to Google, comes back)
- [ ] Dashboard loads after login
- [ ] Can access `/inventory` page (if authorized)

### ✅ Production Mode Tests

- [ ] Flask starts without errors
- [ ] Console shows: `[CONFIG] Running in PRODUCTION mode → sales.globalerc.pt`
- [ ] Flask is listening on `0.0.0.0:5000` (not just localhost)
- [ ] Reverse proxy correctly forwards requests
- [ ] HTTPS works (SSL certificate is valid)
- [ ] Google OAuth redirect URI accepts `https://sales.globalerc.pt/oauth2callback`
- [ ] Can login and access dashboard

---

## How to Check Flask is Listening on Right Interface

### In Development Mode
Should be on `localhost` only:
```powershell
netstat -ano | findstr :5000
```
Look for `127.0.0.1:5000`

### In Production Mode
Should be on all interfaces:
```powershell
netstat -ano | findstr :5000
```
Look for `0.0.0.0:5000`

---

## Quick Diagnostic Commands

### Check if Flask is running
```powershell
$response = Invoke-WebRequest -Uri http://localhost:5000 -UseBasicParsing -ErrorAction SilentlyContinue
if ($response) { "✅ Flask is running" } else { "❌ Flask is not responding" }
```

### Check current mode in console
Look for the `[CONFIG]` message when Flask starts.

### Verify environment variable is set
```powershell
$env:FLASK_MODE
```

---

## Troubleshooting

### Flask won't start in development mode
- ✅ Make sure no other process is using port 5000
- ✅ Kill any existing Python processes: `taskkill /F /IM python.exe`
- ✅ Check syntax: `python -m py_compile app.py`

### Flask won't start in production mode
- ✅ Same as above
- ✅ Make sure you have permission to bind to `0.0.0.0:5000`

### OAuth fails in production
- ✅ Did you update Google Cloud Console with `https://sales.globalerc.pt/oauth2callback`?
- ✅ Is your reverse proxy forwarding headers correctly? (Check nginx config for `X-Forwarded-Proto`)

### Can't access production from other machines
- ✅ Is port 5000 open in firewall?
- ✅ Is reverse proxy listening on port 443 (HTTPS)?
- ✅ Did you configure DNS for `sales.globalerc.pt`?

---

## Switching Between Modes

It's easy to switch:

**Development:**
```powershell
.\run_dev.ps1
```

**Production:**
```powershell
.\run_prod.ps1
```

Or set the environment variable:
```powershell
$env:FLASK_MODE = "development"     # or "production"
python app.py
```

---

## Expected Output

### Development Mode Output:
```
[CONFIG] Running in DEVELOPMENT mode → localhost:5000
Server URL: http://localhost:5000
Mode: DEVELOPMENT
================================================================================

 * Running on http://localhost:5000
 * Press CTRL+C to quit
```

### Production Mode Output:
```
[CONFIG] Running in PRODUCTION mode → sales.globalerc.pt
Server URL: https://sales.globalerc.pt
Mode: PRODUCTION
================================================================================

 * Running on http://0.0.0.0:5000
 * Press CTRL+C to quit
```

---

## Need Help?

If something doesn't work:
1. Check the Flask console output - look for `[CONFIG]` message
2. Run diagnostic command to check port
3. Kill all Python processes and restart
4. Verify environment variables are set correctly
