fix: Auto-detect dev server URL for Local by Flywheel

🐛 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!
This commit is contained in:
dwindown
2025-11-16 13:48:23 +07:00
parent 61825c9ade
commit f77c9b828e
2 changed files with 14 additions and 4 deletions

View File

@@ -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);
}

View File

@@ -108,9 +108,6 @@ class StandaloneAdmin {
}
?>
<!-- WooNooW Assets -->
<link rel="stylesheet" href="<?php echo esc_url( $css_url ); ?>">
<?php
// Print WordPress media library styles (complete set for proper modal)
wp_print_styles( 'media-views' );
@@ -120,6 +117,9 @@ class StandaloneAdmin {
wp_print_styles( 'wp-admin' );
wp_print_styles( 'common' );
?>
<!-- WooNooW Assets -->
<link rel="stylesheet" href="<?php echo esc_url( $css_url ); ?>">
</head>
<body class="woonoow-standalone">
<div id="woonoow-admin-app"></div>