# 📌 Production Deployment - Quick Reference Card

## Your Information

```
Public IP:     78.137.202.90
Local IP:      192.168.10.67
Domain:        sales.globalerc.pt
Old DNS:       94.46.169.199 (WRONG)
New DNS:       78.137.202.90 (CORRECT)
```

---

## 8-Step Deployment (Save this!)

### 1️⃣ Update DNS at Registrar
- [ ] Login to domain registrar (GoDaddy, Namecheap, etc.)
- [ ] Find **A Record** for `sales` or `sales.globalerc.pt`
- [ ] Change value from `94.46.169.199` → `78.137.202.90`
- [ ] Save
- [ ] Wait 5-15 min (test with `nslookup sales.globalerc.pt`)

### 2️⃣ Router Port Forwarding
- [ ] Open browser → `http://192.168.10.1`
- [ ] Login (admin/password)
- [ ] Find **Port Forwarding**
- [ ] Add:
  - | External | Internal IP | Internal Port | Protocol |
    |----------|-------------|---------------|----------|
    | 80 | 192.168.10.67 | 80 | TCP |
    | 443 | 192.168.10.67 | 443 | TCP |
- [ ] Save & restart router

### 3️⃣ Windows Firewall (Run as Admin)
```powershell
New-NetFirewallRule -DisplayName "Sales Dashboard HTTP" `
  -Direction Inbound -Protocol TCP -LocalPort 80 -Action Allow
  
New-NetFirewallRule -DisplayName "Sales Dashboard HTTPS" `
  -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow
```

### 4️⃣ Install Nginx
```powershell
choco install nginx -y
```

### 5️⃣ Get SSL Certificate (Free)
- [ ] Go to **https://zerossl.com**
- [ ] Click **Free SSL Certificate**
- [ ] Enter: `sales.globalerc.pt`
- [ ] Choose **Email Validation**
- [ ] Check email → Click validation link
- [ ] Download as **PEM** format
- [ ] Extract ZIP

### 6️⃣ Copy Certificate Files
```powershell
mkdir C:\nginx\certs -ErrorAction SilentlyContinue

# Copy these files from ZeroSSL to:
Copy-Item "certificate.crt" "C:\nginx\certs\"
Copy-Item "private.key" "C:\nginx\certs\"
Copy-Item "ca_bundle.crt" "C:\nginx\certs\"
```

### 7️⃣ Update Google OAuth
- [ ] Go to **Google Cloud Console**
- [ ] **APIs & Services** → **OAuth 2.0 Client IDs**
- [ ] Add redirect URI:
  ```
  https://sales.globalerc.pt/oauth2callback
  ```

### 8️⃣ Start Services

**Terminal 1 - Flask:**
```powershell
cd "C:\Users\Tiago Rebelo\Desktop\Globale RC\2-Vibe Coding\Sales Dashboard App_VScode"
.\run_prod.ps1
```

**Terminal 2 - Nginx:**
```powershell
cd C:\nginx
.\nginx.exe
```

---

## ✅ Verification

**Test 1: Local:**
```powershell
Invoke-WebRequest -Uri "https://sales.globalerc.pt" -UseBasicParsing | Select-Object StatusCode
# Expected: 200 OK
```

**Test 2: From phone/tablet:**
- Connect to different WiFi (mobile hotspot)
- Open: `https://sales.globalerc.pt/dashboard`
- Should load with 🔒 green padlock

**Test 3: Services:**
```powershell
Get-Process python, nginx  # Both running?
Get-NetTCPConnection -LocalPort 443, 5000  # Both listening?
```

---

## ⚠️ If Something Breaks

| Problem | Fix |
|---------|-----|
| "Can't connect" | Check DNS: `nslookup sales.globalerc.pt` |
| "Certificate error" | Verify cert files exist: `Test-Path C:\nginx\certs\*` |
| "Port timeout" | Check port forwarding in router |
| "Flask not responding" | Restart: `taskkill /F /IM python.exe; .\run_prod.ps1` |
| "Nginx error" | Check logs: `notepad C:\nginx\logs\error.log` |

---

## 📋 Daily Operations

**Every day:**
```powershell
# Check everything is running
Get-Process python, nginx

# Quick health check
Invoke-WebRequest -Uri "https://sales.globalerc.pt" -UseBasicParsing | Select-Object StatusCode
```

**If restarting services:**
```powershell
# Kill & restart
taskkill /F /IM python.exe, nginx.exe 2>$null
Start-Sleep -Seconds 3

# Start fresh (terminal 1)
.\run_prod.ps1

# Start fresh (terminal 2)
cd C:\nginx; .\nginx.exe
```

---

## 📞 Support

For detailed explanations:
- See `DNS_ROUTER_SETUP_GUIDE.md` (full step-by-step)
- See `COMPLETE_OPERATIONS_GUIDE.md` (all operations)

For each router brand specifics, refer to Setup Guide section "Configure Router Port Forwarding"
