Created
July 22, 2026 09:07
-
-
Save me-suzy/49071d01f4d4c108e6c9ebe25c0d5950 to your computer and use it in GitHub Desktop.
01-test-search-local.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| param( | |
| [int]$Port = 8765, | |
| [string]$Query = "2025" | |
| ) | |
| $ErrorActionPreference = "Stop" | |
| $Root = Split-Path -Parent $PSScriptRoot | |
| $Url = "http://127.0.0.1:$Port/search.html?q=$Query" | |
| $ServerProcess = $null | |
| try { | |
| $existing = Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction SilentlyContinue | |
| if (-not $existing) { | |
| $ServerProcess = Start-Process ` | |
| -FilePath python ` | |
| -ArgumentList "-m http.server $Port --bind 127.0.0.1" ` | |
| -WorkingDirectory $Root ` | |
| -WindowStyle Hidden ` | |
| -PassThru | |
| Start-Sleep -Seconds 2 | |
| } | |
| $listening = Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction SilentlyContinue | |
| if (-not $listening) { | |
| throw "Local server is not listening on port $Port." | |
| } | |
| $response = Invoke-WebRequest -Uri $Url -UseBasicParsing -TimeoutSec 10 | |
| [PSCustomObject]@{ | |
| Url = $Url | |
| Status = $response.StatusCode | |
| Length = $response.RawContentLength | |
| HasGoogleEngine = ($response.Content -match "Google Engine") | |
| HasCseScript = ($response.Content -match "(www\.google\.com/cse/cse|cse\.google\.com/cse)\.js") | |
| HasResultsTag = ($response.Content -match "gcse:searchresults-only") | |
| } | Format-List | |
| Write-Host "" | |
| Write-Host "Open this URL in a browser to verify rendered results:" | |
| Write-Host $Url | |
| } | |
| finally { | |
| if ($ServerProcess) { | |
| Stop-Process -Id $ServerProcess.Id -ErrorAction SilentlyContinue | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment