|
| 1 | +# ✅ Fixed: Webhook Tab Now Works Locally! |
| 2 | + |
| 3 | +## What Was Wrong |
| 4 | + |
| 5 | +Your localhost wasn't showing webhook events because: |
| 6 | + |
| 7 | +1. ❌ Frontend was configured with `VITE_BACKEND_BASE_URL=https://dr-cloud-api-dev.trackmangolfdev.com` |
| 8 | +2. ❌ WebhookView component used this URL directly, bypassing the Vite proxy |
| 9 | +3. ❌ Requests went to cloud backend instead of your local server |
| 10 | +4. ❌ Local server (with Azure Storage connection) was being ignored |
| 11 | + |
| 12 | +## What I Fixed |
| 13 | + |
| 14 | +### ✅ Code Change: `src/components/WebhookView.tsx` |
| 15 | + |
| 16 | +Added automatic localhost detection: |
| 17 | + |
| 18 | +```typescript |
| 19 | +// Detect if running on localhost to use Vite proxy |
| 20 | +const isLocalhost = windowOrigin.includes('localhost') || windowOrigin.includes('127.0.0.1'); |
| 21 | +const normalizedBase = isLocalhost ? '' : String(viteEnvBase || windowOrigin || '').replace(/\/$/, ''); |
| 22 | +``` |
| 23 | + |
| 24 | +**How it works:** |
| 25 | +- **On localhost** (http://localhost:5000): Uses relative URLs → Goes through Vite proxy → Your local server |
| 26 | +- **On cloud** (https://...): Uses `VITE_BACKEND_BASE_URL` → Direct to cloud backend |
| 27 | + |
| 28 | +### ✅ Now Your Setup Works Like This: |
| 29 | + |
| 30 | +``` |
| 31 | +┌──────────────────────────────────────────────────┐ |
| 32 | +│ Frontend (localhost:5000) │ |
| 33 | +│ ↓ │ |
| 34 | +│ WebhookView detects localhost ✓ │ |
| 35 | +│ ↓ │ |
| 36 | +│ Uses relative URL: /api/webhook/... │ |
| 37 | +│ ↓ │ |
| 38 | +│ Vite Proxy (configured in vite.config.ts) │ |
| 39 | +│ ↓ │ |
| 40 | +│ Forwards to: localhost:4000/api/webhook/... │ |
| 41 | +│ ↓ │ |
| 42 | +│ Local Server (with Azure Storage connection) │ |
| 43 | +│ ↓ │ |
| 44 | +│ Reads from Azure Table Storage │ |
| 45 | +│ ↓ │ |
| 46 | +│ Returns ALL events (same as cloud!) ✅ │ |
| 47 | +└──────────────────────────────────────────────────┘ |
| 48 | +``` |
| 49 | + |
| 50 | +## How to Test |
| 51 | + |
| 52 | +### Step 1: Restart Frontend (to pick up code changes) |
| 53 | + |
| 54 | +```bash |
| 55 | +# Stop the current dev server (Ctrl+C) |
| 56 | +npm run dev |
| 57 | +``` |
| 58 | + |
| 59 | +### Step 2: Verify Configuration |
| 60 | + |
| 61 | +```powershell |
| 62 | +.\scripts\test-webhook-integration.ps1 |
| 63 | +``` |
| 64 | + |
| 65 | +This will check: |
| 66 | +- ✅ Local server running |
| 67 | +- ✅ Azure Storage connected |
| 68 | +- ✅ Vite proxy working |
| 69 | +- ✅ Events accessible |
| 70 | + |
| 71 | +### Step 3: Test in Browser |
| 72 | + |
| 73 | +1. Open http://localhost:5000 (or your port) |
| 74 | +2. Login |
| 75 | +3. Select a bay |
| 76 | +4. Go to **Webhook** tab |
| 77 | +5. **You should now see events!** 🎉 |
| 78 | + |
| 79 | +### Step 4: Verify Network Request |
| 80 | + |
| 81 | +Open DevTools → Network tab: |
| 82 | +- ✅ Request should be: `http://localhost:5000/api/webhook/YOUR_PATH/events` |
| 83 | +- ✅ Should NOT be: `https://dr-cloud-api-dev.trackmangolfdev.com/...` |
| 84 | + |
| 85 | +## What This Means |
| 86 | + |
| 87 | +### ✅ Benefits |
| 88 | + |
| 89 | +1. **Same data everywhere**: Local dev sees the same events as cloud |
| 90 | +2. **No config changes needed**: Works automatically when on localhost |
| 91 | +3. **No .env changes**: Can keep `VITE_BACKEND_BASE_URL` set to cloud |
| 92 | +4. **Team-friendly**: Other developers get the same experience |
| 93 | +5. **Deployment-ready**: Code works correctly in both environments |
| 94 | + |
| 95 | +### 📊 Comparison |
| 96 | + |
| 97 | +**Before (Not Working):** |
| 98 | +``` |
| 99 | +localhost:5000 → cloud backend → cloud storage ❌ |
| 100 | +``` |
| 101 | + |
| 102 | +**After (Working):** |
| 103 | +``` |
| 104 | +localhost:5000 → proxy → localhost:4000 → Azure Storage ✅ |
| 105 | +``` |
| 106 | + |
| 107 | +## Files Modified |
| 108 | + |
| 109 | +1. ✅ `src/components/WebhookView.tsx` - Auto-detect localhost |
| 110 | +2. ✅ `server/.env` - Has Azure Storage connection string |
| 111 | + |
| 112 | +## Files Created (Documentation) |
| 113 | + |
| 114 | +1. 📄 `WEBHOOK_LOCAL_FIX.md` - Detailed explanation |
| 115 | +2. 📄 `scripts/test-webhook-integration.ps1` - Test script |
| 116 | +3. 📄 `FIXED_WEBHOOK_SUMMARY.md` - This file |
| 117 | + |
| 118 | +## Troubleshooting |
| 119 | + |
| 120 | +### Still Not Seeing Events? |
| 121 | + |
| 122 | +**Check 1: Is server running?** |
| 123 | +```bash |
| 124 | +cd server |
| 125 | +npm run dev |
| 126 | +``` |
| 127 | + |
| 128 | +Look for: |
| 129 | +``` |
| 130 | +✅ Azure Table Storage connected: WebhookEvents |
| 131 | +``` |
| 132 | + |
| 133 | +**Check 2: Is connection string configured?** |
| 134 | +```powershell |
| 135 | +.\scripts\verify-local-storage.ps1 |
| 136 | +``` |
| 137 | + |
| 138 | +**Check 3: Are there events in storage?** |
| 139 | +The events must have been sent to your webhook URL in Azure. If you haven't set up the webhook subscription yet, there won't be any events to display. |
| 140 | + |
| 141 | +**Check 4: Is frontend using proxy?** |
| 142 | +Open DevTools → Network tab → Look for `/api/webhook/` requests |
| 143 | +- Should go to `localhost:5000/api/...` (which proxies to `:4000`) |
| 144 | +- Should NOT go directly to `dr-cloud-api-dev.trackmangolfdev.com` |
| 145 | + |
| 146 | +### How to Verify Proxy is Working |
| 147 | + |
| 148 | +```bash |
| 149 | +# With server running on :4000 and frontend on :5000 |
| 150 | +curl http://localhost:5000/api/webhook/YOUR_PATH/events |
| 151 | +``` |
| 152 | + |
| 153 | +Should return events from your local server. |
| 154 | + |
| 155 | +## Next Steps |
| 156 | + |
| 157 | +1. ✅ Code fix applied |
| 158 | +2. 🔄 Restart frontend (`npm run dev`) |
| 159 | +3. 🧪 Run test script (`.\scripts\test-webhook-integration.ps1`) |
| 160 | +4. 🌐 Open http://localhost:5000 → Webhook tab |
| 161 | +5. 🎉 See your events! |
| 162 | + |
| 163 | +## Need More Help? |
| 164 | + |
| 165 | +- 📖 Read: `WEBHOOK_LOCAL_FIX.md` for detailed options |
| 166 | +- 📖 Read: `LOCAL_AZURE_STORAGE_SETUP.md` for storage setup |
| 167 | +- 🧪 Run: `.\scripts\test-webhook-integration.ps1` for diagnostics |
| 168 | +- 🔍 Run: `.\scripts\verify-local-storage.ps1` for config check |
| 169 | + |
| 170 | +--- |
| 171 | + |
| 172 | +**The fix is automatic!** Just restart your frontend and it should work. 🚀 |
0 commit comments