75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Start Dashboard Server for Protocol Mapping Testing
|
|
"""
|
|
|
|
import os
|
|
import asyncio
|
|
import uvicorn
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.templating import Jinja2Templates
|
|
from fastapi.responses import HTMLResponse
|
|
from fastapi import Request
|
|
|
|
from src.dashboard.api import dashboard_router
|
|
from src.dashboard.templates import DASHBOARD_HTML
|
|
from src.discovery.protocol_discovery_persistent import persistent_discovery_service
|
|
|
|
# Create FastAPI app
|
|
app = FastAPI(title="Calejo Control Adapter Dashboard", version="1.0.0")
|
|
|
|
# Include dashboard router
|
|
app.include_router(dashboard_router)
|
|
|
|
# Serve static files
|
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
|
|
@app.get("/", response_class=HTMLResponse)
|
|
async def serve_dashboard(request: Request):
|
|
"""Serve the main dashboard interface"""
|
|
return HTMLResponse(DASHBOARD_HTML)
|
|
|
|
@app.get("/dashboard", response_class=HTMLResponse)
|
|
async def serve_dashboard_alt(request: Request):
|
|
"""Alternative route for dashboard"""
|
|
return HTMLResponse(DASHBOARD_HTML)
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
"""Health check endpoint"""
|
|
return {"status": "healthy", "service": "dashboard"}
|
|
|
|
async def initialize_services():
|
|
"""Initialize services before starting the server"""
|
|
try:
|
|
print("🔄 Starting persistent discovery service initialization...")
|
|
await persistent_discovery_service.initialize()
|
|
print("✅ Persistent discovery service initialized")
|
|
|
|
# Test that it's working
|
|
status = persistent_discovery_service.get_discovery_status()
|
|
print(f"📊 Discovery status: {status}")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Failed to initialize persistent discovery service: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
if __name__ == "__main__":
|
|
# Get port from environment variable or default to 8080
|
|
port = int(os.getenv("REST_API_PORT", "8080"))
|
|
|
|
print("🚀 Starting Calejo Control Adapter Dashboard...")
|
|
print(f"📊 Dashboard available at: http://localhost:{port}")
|
|
print("📊 Protocol Mapping tab should be visible in the navigation")
|
|
|
|
# Initialize services
|
|
asyncio.run(initialize_services())
|
|
|
|
uvicorn.run(
|
|
app,
|
|
host="0.0.0.0",
|
|
port=port,
|
|
log_level="info"
|
|
) |