-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-api-connectivity.ps1
More file actions
74 lines (61 loc) · 3.62 KB
/
Copy pathtest-api-connectivity.ps1
File metadata and controls
74 lines (61 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# PowerShell script to test if the backend API is running and responsive
# Run this to check if your API server is working properly
$apiUrl = "https://localhost:7037/api/ChargingStations"
Write-Host "🔍 Testing backend API connectivity..." -ForegroundColor Yellow
Write-Host "API URL: $apiUrl" -ForegroundColor Cyan
try {
# Test basic connectivity (ignore SSL certificate issues for localhost)
Write-Host "`n📞 Testing GET /api/ChargingStations..." -ForegroundColor White
# Create a web request with SSL bypass for localhost
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$response = Invoke-RestMethod -Uri $apiUrl -Method GET -TimeoutSec 10
Write-Host "✅ API is responsive!" -ForegroundColor Green
Write-Host "Response data:" -ForegroundColor White
if ($response -is [array]) {
Write-Host "Found $($response.Count) stations:" -ForegroundColor Green
foreach ($station in $response) {
Write-Host " - ID: $($station.id)" -ForegroundColor Gray
Write-Host " Name: $($station.name)" -ForegroundColor White
Write-Host " Location: $($station.location)" -ForegroundColor White
Write-Host " Type: $($station.type)" -ForegroundColor White
Write-Host " Available Slots: $($station.availableSlots)" -ForegroundColor White
Write-Host " Active: $($station.isActive)" -ForegroundColor White
Write-Host " ---" -ForegroundColor Gray
}
} else {
Write-Host "Response: $response" -ForegroundColor White
}
Write-Host "`n🎉 Backend API is working! The frontend should be able to connect." -ForegroundColor Green
} catch {
Write-Host "❌ API test failed!" -ForegroundColor Red
Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
if ($_.Exception.Message -like "*Could not establish trust relationship*") {
Write-Host "⚠️ SSL certificate issue - this is normal for localhost development" -ForegroundColor Yellow
}
if ($_.Exception.Message -like "*No connection could be made*") {
Write-Host "⚠️ Connection refused - API server may not be running" -ForegroundColor Yellow
Write-Host "`n🔧 To start your API server:" -ForegroundColor Cyan
Write-Host "1. Open a terminal in the ev-station-booking-system-api folder" -ForegroundColor White
Write-Host "2. Run: dotnet run" -ForegroundColor White
Write-Host "3. Wait for 'Now listening on: https://localhost:7037'" -ForegroundColor White
}
Write-Host "`n🔍 Troubleshooting checklist:" -ForegroundColor Yellow
Write-Host "1. ✓ Check if API server is running (dotnet run)" -ForegroundColor White
Write-Host "2. ✓ Verify it's listening on https://localhost:7037" -ForegroundColor White
Write-Host "3. ✓ Check if MongoDB connection is working" -ForegroundColor White
Write-Host "4. ✓ Ensure ChargingStations collection exists in MongoDB" -ForegroundColor White
}
Write-Host "`nPress any key to continue..." -ForegroundColor Gray
$host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null