we good! note its working check da ip

This commit is contained in:
2025-12-04 22:44:01 -05:00
parent 97edaa5d51
commit 77f2f1bf5b
6 changed files with 115 additions and 18 deletions
+43 -4
View File
@@ -3,6 +3,8 @@ VitalLink Backend API
FastAPI server for managing patients, wristbands, and real-time data
"""
import os
import socket
from fastapi import FastAPI, WebSocket, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
@@ -16,6 +18,37 @@ from collections import defaultdict
from triage_engine import TriageEngine, VitalSigns, TriageLevel, triage_from_vitals
from database import VitalLinkDatabase
# ============================================================================
# NETWORK UTILITIES
# ============================================================================
def get_host_ip():
"""
Returns the actual LAN IP address.
Priority:
1. HOST_IP environment variable (from docker-compose)
2. Automatic detection via socket
3. Fallback to localhost
"""
# 1. Check Environment Variable (The "Single Place")
env_ip = os.getenv("HOST_IP")
if env_ip:
return env_ip
# 2. Auto-detect LAN IP
try:
# We don't actually connect, just check how we WOULD connect to Google
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(0)
s.connect(("8.8.8.8", 1))
ip = s.getsockname()[0]
s.close()
return ip
except Exception:
return "127.0.0.1"
# ============================================================================
# LIFESPAN MANAGEMENT
# ============================================================================
@@ -25,18 +58,24 @@ from database import VitalLinkDatabase
async def lifespan(app: FastAPI):
# Startup
global db
# GET THE IP
host_ip = get_host_ip()
print("=" * 80)
print("VitalLink Backend API Started")
print(f"VitalLink Backend API Started on {host_ip}")
print("=" * 80)
# Initialize database
db = VitalLinkDatabase("vitallink.db")
await db.initialize()
print("API Documentation: http://localhost:8000/docs")
print("WebSocket Endpoint: ws://localhost:8000/ws")
print("Database: vitallink.db")
# Print useful clickable links for the developer
print(f"API Documentation: http://{host_ip}:8000/docs")
print(f"Frontend Dashboard: http://{host_ip}:5173")
print(f"WebSocket Endpoint: ws://{host_ip}:8000/ws")
print("=" * 80)
yield
# Shutdown
if db: