52 lines
2.4 KiB
PowerShell
52 lines
2.4 KiB
PowerShell
# Get the active network interface IP address (excluding virtual and loopback adapters)
|
|
Write-Host "Checking active network adapters..." -ForegroundColor Cyan
|
|
|
|
$ipAddress = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {
|
|
$_.IPAddress -notlike "127.*" -and
|
|
$_.IPAddress -notlike "169.254.*" -and
|
|
$_.InterfaceAlias -notlike "*vEthernet*" -and
|
|
$_.InterfaceAlias -notlike "*WSL*" -and
|
|
$_.IPAddress -notlike "192.168.56.*"
|
|
} | Select-Object -ExpandProperty IPAddress -First 1)
|
|
|
|
if (-not $ipAddress) {
|
|
Write-Host "[-] No active LAN IP address found! Falling back to 127.0.0.1" -ForegroundColor Yellow
|
|
$ipAddress = "127.0.0.1"
|
|
} else {
|
|
Write-Host "[+] Found active Host IP: $ipAddress" -ForegroundColor Green
|
|
}
|
|
|
|
# Update Flutter Configuration
|
|
$configFile = "lib/config/app_config.dart"
|
|
if (Test-Path $configFile) {
|
|
$content = Get-Content $configFile -Raw
|
|
$pattern = "(static const String _lanBaseUrl = 'http://)([^:]+)(:8000/api/v1';)"
|
|
if ($content -match $pattern) {
|
|
$content = $content -replace $pattern, ('${1}' + $ipAddress + '${3}')
|
|
Set-Content $configFile $content -NoNewline
|
|
Write-Host "[+] Synchronized local IP address ($ipAddress) to Flutter configuration." -ForegroundColor Green
|
|
} else {
|
|
Write-Host "[-] Warning: _lanBaseUrl pattern not found in $configFile." -ForegroundColor Yellow
|
|
}
|
|
} else {
|
|
Write-Host "[-] Warning: Flutter config file '$configFile' not found. Skip updating local IP." -ForegroundColor Yellow
|
|
}
|
|
|
|
# Start ngrok
|
|
Write-Host "`nStarting Ngrok tunnel..." -ForegroundColor Cyan
|
|
Write-Host "Exposing: http://localhost:8000" -ForegroundColor Cyan
|
|
Write-Host "Public URL: https://unlocated-waylon-potently.ngrok-free.dev" -ForegroundColor Cyan
|
|
|
|
# Check if ngrok is available
|
|
$ngrokCmd = Get-Command ngrok -ErrorAction SilentlyContinue
|
|
if ($ngrokCmd) {
|
|
Write-Host "[+] Launching ngrok in a new window..." -ForegroundColor Green
|
|
Start-Process ngrok -ArgumentList "http", "--domain=unlocated-waylon-potently.ngrok-free.dev", "8000"
|
|
Write-Host "[+] Tunnel launched successfully!" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "[-] Error: 'ngrok' command not found in your system PATH." -ForegroundColor Red
|
|
Write-Host " Please ensure ngrok is installed and added to your environment variables." -ForegroundColor Yellow
|
|
}
|
|
|
|
Write-Host "`nDone! Your Flutter app can now connect locally via WiFi ($ipAddress) or publicly via Ngrok." -ForegroundColor Green
|