From f77c9b828e83c70baf5a2dffeca1c5cbef327c49 Mon Sep 17 00:00:00 2001 From: dwindown Date: Sun, 16 Nov 2025 13:48:23 +0700 Subject: [PATCH] fix: Auto-detect dev server URL for Local by Flywheel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 Problem: - Dev server hardcoded to http://localhost:5173 - Local by Flywheel uses *.local domains with HTTPS - Dev mode was blank page (couldn't connect to Vite) ✅ Solution: Auto-detect dev server URL based on current host: - Reads $_SERVER['HTTP_HOST'] - Detects *.local domains (Local by Flywheel) - Uses HTTPS for *.local domains - Falls back to HTTP for localhost 📝 Examples: - woonoow.local → https://woonoow.local:5173 - localhost → http://localhost:5173 - example.test → http://example.test:5173 🎯 Result: - Dev mode works on Local by Flywheel - Dev mode works on standard localhost - No hardcoded URLs - Still filterable via 'woonoow/admin_dev_server' 💡 Usage: 1. Set WOONOOW_ADMIN_DEV=true in wp-config.php 2. Run: npm run dev 3. Visit wp-admin - Vite HMR works! --- includes/Admin/Assets.php | 12 +++++++++++- includes/Admin/StandaloneAdmin.php | 6 +++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/includes/Admin/Assets.php b/includes/Admin/Assets.php index f781833..5c9f16c 100644 --- a/includes/Admin/Assets.php +++ b/includes/Admin/Assets.php @@ -289,7 +289,17 @@ class Assets { /** Dev server URL (filterable) */ private static function dev_server_url(): string { - $default = 'http://localhost:5173'; + // Auto-detect based on current host (for Local by Flywheel compatibility) + $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; + $protocol = is_ssl() ? 'https' : 'http'; + + // If using *.local domain (Local by Flywheel), use HTTPS + if (strpos($host, '.local') !== false) { + $protocol = 'https'; + } + + $default = $protocol . '://' . $host . ':5173'; + /** Filter: change dev server URL if needed */ return (string) apply_filters('woonoow/admin_dev_server', $default); } diff --git a/includes/Admin/StandaloneAdmin.php b/includes/Admin/StandaloneAdmin.php index 75c17f5..770d8e1 100644 --- a/includes/Admin/StandaloneAdmin.php +++ b/includes/Admin/StandaloneAdmin.php @@ -108,9 +108,6 @@ class StandaloneAdmin { } ?> - - - + + +