start_local_static.ps1 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Local static JSON HTTP servers for AccountServer config fetch
  2. # Run in elevated PowerShell if port 80 fails
  3. $root = Split-Path -Parent $PSScriptRoot
  4. $port80Dir = Join-Path $root "local_static\port80"
  5. $port8000Dir = Join-Path $root "local_static\port8000"
  6. function Test-PortListening([int]$Port) {
  7. $conn = Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction SilentlyContinue
  8. return $null -ne $conn
  9. }
  10. if (Test-PortListening 80) {
  11. Write-Host "[skip] port 80 already listening"
  12. } else {
  13. Write-Host "[start] port 80 -> $port80Dir"
  14. Start-Process python -ArgumentList "-m http.server 80 --directory `"$port80Dir`"" -WindowStyle Minimized
  15. }
  16. if (Test-PortListening 8000) {
  17. Write-Host "[skip] port 8000 already listening"
  18. } else {
  19. Write-Host "[start] port 8000 -> $port8000Dir"
  20. Start-Process python -ArgumentList "-m http.server 8000 --directory `"$port8000Dir`"" -WindowStyle Minimized
  21. }
  22. Start-Sleep -Seconds 2
  23. Write-Host ""
  24. Write-Host "verify:"
  25. foreach ($url in @(
  26. "http://127.0.0.1/cjw_60000_stop_server.json",
  27. "http://127.0.0.1:8000/serverlist.json"
  28. )) {
  29. try {
  30. $r = Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 5
  31. Write-Host " OK $url HTTP $($r.StatusCode)"
  32. } catch {
  33. Write-Host " FAIL $url $($_.Exception.Message)"
  34. }
  35. }