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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user