# Diagnostic script for TestDataDB on AD2
Write-Output "=== Node Process ==="
Get-CimInstance Win32_Process -Filter "Name='node.exe'" | Select-Object ProcessId, CommandLine | Format-List

Write-Output "=== HTTP Test ==="
try {
    $r = Invoke-WebRequest -Uri "http://localhost:3000/" -UseBasicParsing -TimeoutSec 10
    Write-Output "Root page status: $($r.StatusCode)"
    Write-Output "Content length: $($r.Content.Length)"
    Write-Output "First 200 chars: $($r.Content.Substring(0, [Math]::Min(200, $r.Content.Length)))"
} catch {
    Write-Output "Root page ERROR: $($_.Exception.Message)"
}

Write-Output "`n=== API Test ==="
try {
    $r = Invoke-WebRequest -Uri "http://localhost:3000/api/stats" -UseBasicParsing -TimeoutSec 10
    Write-Output "API status: $($r.StatusCode)"
    Write-Output "First 200 chars: $($r.Content.Substring(0, [Math]::Min(200, $r.Content.Length)))"
} catch {
    Write-Output "API ERROR: $($_.Exception.Message)"
}

Write-Output "`n=== Service Log Files ==="
Get-ChildItem "C:\Shares\testdatadb\logs\" -ErrorAction SilentlyContinue | Format-Table Name, Length, LastWriteTime

Write-Output "`n=== Recent Event Log ==="
Get-EventLog -LogName Application -Newest 5 -Source "*node*" -ErrorAction SilentlyContinue | Format-List
