from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import HTMLResponse import shutil import uvicorn app = FastAPI(title="Disk Space Monitor", description="A simple API to monitor disk space") # Add CORS middleware app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) def get_disk_space(): """Get disk space information""" total, used, free = shutil.disk_usage("/") return { "total_gb": round(total / (1024**3), 2), "used_gb": round(used / (1024**3), 2), "free_gb": round(free / (1024**3), 2), "used_percentage": round((used / total) * 100, 2) } @app.get("/") async def root(): """Root endpoint with HTML interface""" disk_info = get_disk_space() html_content = f"""
API Endpoints: /api/disk-space | /docs