File size: 5,117 Bytes
9d79680
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# ============================================================
# AJ API - COMPLETE STARTUP SCRIPT
# Created by AJ STUDIOZ
# ============================================================

Write-Host ""
Write-Host "============================================================" -ForegroundColor Cyan
Write-Host "   AJ API SERVER - COMPLETE STARTUP" -ForegroundColor Green
Write-Host "   Created by AJ STUDIOZ" -ForegroundColor Yellow
Write-Host "============================================================" -ForegroundColor Cyan
Write-Host ""

# Get current directory
$ProjectPath = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $ProjectPath

# Step 1: Start API Server
Write-Host "[1/3] Starting API Server..." -ForegroundColor Yellow
Start-Process python -ArgumentList "api_server.py" -WindowStyle Minimized
Start-Sleep -Seconds 5

# Test if API is running
try {
    $response = Invoke-WebRequest -Uri "http://localhost:5000/health" -UseBasicParsing -ErrorAction SilentlyContinue
    Write-Host "      ✓ API Server is running on port 5000" -ForegroundColor Green
} catch {
    Write-Host "      ⚠ API may still be starting..." -ForegroundColor Yellow
}

# Step 2: Start ngrok
Write-Host ""
Write-Host "[2/3] Starting ngrok tunnel..." -ForegroundColor Yellow
Start-Process ngrok -ArgumentList "http 5000" -WindowStyle Minimized
Start-Sleep -Seconds 6

Write-Host "      ✓ ngrok tunnel started" -ForegroundColor Green

# Step 3: Get ngrok URL
Write-Host ""
Write-Host "[3/3] Getting ngrok URL..." -ForegroundColor Yellow
Start-Sleep -Seconds 2

try {
    $ngrokApi = Invoke-RestMethod -Uri "http://localhost:4040/api/tunnels" -ErrorAction SilentlyContinue
    $publicUrl = $ngrokApi.tunnels[0].public_url
    
    Write-Host ""
    Write-Host "============================================================" -ForegroundColor Cyan
    Write-Host "   STARTUP COMPLETE!" -ForegroundColor Green
    Write-Host "============================================================" -ForegroundColor Cyan
    Write-Host ""
    Write-Host "Your ngrok Public URL:" -ForegroundColor Yellow
    Write-Host "$publicUrl" -ForegroundColor White
    Write-Host ""
    Write-Host "============================================================" -ForegroundColor Cyan
    Write-Host "   CURL TEST COMMANDS" -ForegroundColor Green
    Write-Host "============================================================" -ForegroundColor Cyan
    Write-Host ""
    
    Write-Host "1. Health Check (GET):" -ForegroundColor Yellow
    Write-Host "curl -X GET `"$publicUrl/health`" -H `"ngrok-skip-browser-warning: true`"" -ForegroundColor White
    Write-Host ""
    
    Write-Host "2. API Info (GET):" -ForegroundColor Yellow
    Write-Host "curl -X GET `"$publicUrl/api/info`" -H `"ngrok-skip-browser-warning: true`"" -ForegroundColor White
    Write-Host ""
    
    Write-Host "3. Chat Endpoint (POST):" -ForegroundColor Yellow
    Write-Host "curl -X POST `"$publicUrl/api/chat`" -H `"Content-Type: application/json`" -H `"ngrok-skip-browser-warning: true`" -d '{`"message`":`"Hello AJ, how are you?`"}'" -ForegroundColor White
    Write-Host ""
    
    Write-Host "4. Home Page (GET):" -ForegroundColor Yellow
    Write-Host "curl -X GET `"$publicUrl/`" -H `"ngrok-skip-browser-warning: true`"" -ForegroundColor White
    Write-Host ""
    
    Write-Host "============================================================" -ForegroundColor Cyan
    Write-Host "   FOR REQBIN.COM" -ForegroundColor Green
    Write-Host "============================================================" -ForegroundColor Cyan
    Write-Host ""
    Write-Host "URL:" -ForegroundColor Yellow
    Write-Host "$publicUrl/api/chat" -ForegroundColor White
    Write-Host ""
    Write-Host "Method: POST" -ForegroundColor Yellow
    Write-Host ""
    Write-Host "Headers:" -ForegroundColor Yellow
    Write-Host "  Content-Type: application/json" -ForegroundColor White
    Write-Host "  ngrok-skip-browser-warning: true" -ForegroundColor White
    Write-Host ""
    Write-Host "Body (JSON):" -ForegroundColor Yellow
    Write-Host '{' -ForegroundColor White
    Write-Host '  "message": "Hello AJ, tell me a joke"' -ForegroundColor White
    Write-Host '}' -ForegroundColor White
    Write-Host ""
    
    Write-Host "============================================================" -ForegroundColor Cyan
    Write-Host "ngrok Dashboard: http://localhost:4040" -ForegroundColor Cyan
    Write-Host "============================================================" -ForegroundColor Cyan
    Write-Host ""
    Write-Host "Press any key to open ngrok dashboard..." -ForegroundColor Yellow
    $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
    Start-Process "http://localhost:4040"
    
} catch {
    Write-Host "      ⚠ Could not retrieve ngrok URL" -ForegroundColor Red
    Write-Host "      Please visit http://localhost:4040 to get your URL" -ForegroundColor Yellow
}

Write-Host ""
Write-Host "Servers are running in the background." -ForegroundColor Green
Write-Host "To stop them, close the Python and ngrok windows." -ForegroundColor Yellow
Write-Host ""