Yuvan666 commited on
Commit
9fa39cc
·
1 Parent(s): d5cc18e

fix: port 8888 alignment and tunnel token configuration for silent fix

Browse files
Files changed (2) hide show
  1. app.py +14 -33
  2. supervisord.conf +7 -2
app.py CHANGED
@@ -1,7 +1,8 @@
1
  """
2
- Stealth Browser Stack - FastAPI on 0.0.0.0:7860
3
- ================================================
4
- Note: noVNC handles 7860, this is a backup API server on 8000
 
5
  """
6
 
7
  import os
@@ -19,7 +20,7 @@ logger = logging.getLogger(__name__)
19
 
20
  from agent import BrowserSession, validate_order
21
 
22
- app = FastAPI(title="Stealth Browser Worker", version="2.0.0")
23
 
24
  app.add_middleware(
25
  CORSMiddleware,
@@ -50,10 +51,9 @@ class TaskResponse(BaseModel):
50
  @app.get("/")
51
  async def root():
52
  return {
53
- "service": "Stealth Browser Worker",
54
- "status": "running",
55
- "display": os.environ.get("DISPLAY", "NOT SET"),
56
- "tunnel": "cloudflared active"
57
  }
58
 
59
 
@@ -62,17 +62,14 @@ async def health():
62
  return {
63
  "status": "healthy",
64
  "display": os.environ.get("DISPLAY", ":99"),
65
- "browser_active": browser_session is not None and browser_session.is_active,
66
- "timestamp": datetime.now().isoformat()
67
  }
68
 
69
 
70
  @app.post("/run-task", response_model=TaskResponse)
71
  async def run_task(request: TaskRequest):
72
  global browser_session
73
-
74
  start_time = datetime.now()
75
- logger.info(f"📥 Task: {request.task_id} ({request.task_type})")
76
 
77
  try:
78
  if request.task_type in ["validate_order", "validate_email"]:
@@ -88,39 +85,23 @@ async def run_task(request: TaskRequest):
88
  execution_time_ms=execution_time
89
  )
90
  else:
91
- raise HTTPException(status_code=400, detail=f"Unknown task_type: {request.task_type}")
92
 
93
  except Exception as e:
94
- execution_time = int((datetime.now() - start_time).total_seconds() * 1000)
95
- logger.error(f"❌ Task {request.task_id} failed: {e}")
96
- return TaskResponse(task_id=request.task_id, status="error", error=str(e), execution_time_ms=execution_time)
97
 
98
 
99
  @app.on_event("startup")
100
  async def startup():
101
  global browser_session
102
- logger.info("🚀 Stealth Browser Stack starting...")
103
- logger.info(f"📺 Display: {os.environ.get('DISPLAY', ':99')}")
104
-
105
  try:
106
  browser_session = await BrowserSession.create()
107
  logger.info("✅ Persistent browser session created!")
108
  except Exception as e:
109
- logger.error(f"⚠️ Could not create browser session: {e}")
110
- browser_session = None
111
-
112
- logger.info("✅ Worker ready!")
113
-
114
-
115
- @app.on_event("shutdown")
116
- async def shutdown():
117
- global browser_session
118
- if browser_session:
119
- await browser_session.close()
120
- logger.info("🔌 Worker shutdown complete.")
121
 
122
 
123
  if __name__ == "__main__":
124
  import uvicorn
125
- # Agent runs on port 8000, noVNC handles 7860
126
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
1
  """
2
+ Stealth Browser Stack - FastAPI on Port 8888
3
+ =============================================
4
+ This handles healthchecks and API tasks.
5
+ noVNC moved to 6080 to avoid conflict.
6
  """
7
 
8
  import os
 
20
 
21
  from agent import BrowserSession, validate_order
22
 
23
+ app = FastAPI(title="Stealth Browser Worker", version="2.5.0")
24
 
25
  app.add_middleware(
26
  CORSMiddleware,
 
51
  @app.get("/")
52
  async def root():
53
  return {
54
+ "service": "AI System Bridge",
55
+ "status": "active",
56
+ "timestamp": datetime.now().isoformat()
 
57
  }
58
 
59
 
 
62
  return {
63
  "status": "healthy",
64
  "display": os.environ.get("DISPLAY", ":99"),
65
+ "browser": browser_session is not None and browser_session.is_active
 
66
  }
67
 
68
 
69
  @app.post("/run-task", response_model=TaskResponse)
70
  async def run_task(request: TaskRequest):
71
  global browser_session
 
72
  start_time = datetime.now()
 
73
 
74
  try:
75
  if request.task_type in ["validate_order", "validate_email"]:
 
85
  execution_time_ms=execution_time
86
  )
87
  else:
88
+ raise HTTPException(status_code=400, detail="Invalid task_type")
89
 
90
  except Exception as e:
91
+ return TaskResponse(task_id=request.task_id, status="error", error=str(e))
 
 
92
 
93
 
94
  @app.on_event("startup")
95
  async def startup():
96
  global browser_session
 
 
 
97
  try:
98
  browser_session = await BrowserSession.create()
99
  logger.info("✅ Persistent browser session created!")
100
  except Exception as e:
101
+ logger.error(f"⚠️ Browser fail: {e}")
 
 
 
 
 
 
 
 
 
 
 
102
 
103
 
104
  if __name__ == "__main__":
105
  import uvicorn
106
+ # Port 8888 for HF healthcheck
107
+ uvicorn.run(app, host="0.0.0.0", port=8888)
supervisord.conf CHANGED
@@ -1,4 +1,6 @@
1
- ; Process Supervisor Configuration
 
 
2
 
3
  [supervisord]
4
  nodaemon=true
@@ -34,8 +36,9 @@ stdout_logfile_maxbytes=0
34
  stderr_logfile=/dev/stderr
35
  stderr_logfile_maxbytes=0
36
 
 
37
  [program:web_portal]
38
- command=/bin/bash -c "sleep 5 && /opt/portal/utils/novnc_proxy --vnc localhost:5900 --listen 0.0.0.0:8888 --web /opt/portal"
39
  autorestart=true
40
  priority=400
41
  stdout_logfile=/dev/stdout
@@ -44,6 +47,7 @@ stderr_logfile=/dev/stderr
44
  stderr_logfile_maxbytes=0
45
 
46
  [program:secure_tunnel]
 
47
  command=cloudflared tunnel --no-autoupdate run --token %(ENV_CLOUDFLARE_TUNNEL_TOKEN)s
48
  autorestart=true
49
  priority=450
@@ -53,6 +57,7 @@ stderr_logfile=/dev/stderr
53
  stderr_logfile_maxbytes=0
54
 
55
  [program:agent]
 
56
  command=/bin/bash -c "sleep 12 && DISPLAY=:99 python /app/app.py"
57
  directory=/app
58
  environment=DISPLAY=":99"
 
1
+ ; =============================================================================
2
+ ; Stealth Supervisor Configuration
3
+ ; =============================================================================
4
 
5
  [supervisord]
6
  nodaemon=true
 
36
  stderr_logfile=/dev/stderr
37
  stderr_logfile_maxbytes=0
38
 
39
+ ; Web portal moved to 6080 (internal) to avoid conflict with app.py on 8888
40
  [program:web_portal]
41
+ command=/bin/bash -c "sleep 5 && /opt/portal/utils/novnc_proxy --vnc localhost:5900 --listen 0.0.0.0:6080 --web /opt/portal"
42
  autorestart=true
43
  priority=400
44
  stdout_logfile=/dev/stdout
 
47
  stderr_logfile_maxbytes=0
48
 
49
  [program:secure_tunnel]
50
+ ; Cloudflare tunnel connects to web_portal on 6080
51
  command=cloudflared tunnel --no-autoupdate run --token %(ENV_CLOUDFLARE_TUNNEL_TOKEN)s
52
  autorestart=true
53
  priority=450
 
57
  stderr_logfile_maxbytes=0
58
 
59
  [program:agent]
60
+ ; Main agent on 8888 for HF healthcheck
61
  command=/bin/bash -c "sleep 12 && DISPLAY=:99 python /app/app.py"
62
  directory=/app
63
  environment=DISPLAY=":99"