#!/usr/bin/env python3 """ Simple test server for frontend testing """ import os from pathlib import Path from datetime import datetime from fastapi import FastAPI, HTTPException from fastapi.responses import FileResponse, HTMLResponse from fastapi.staticfiles import StaticFiles import aiofiles app = FastAPI(title="Quixotic Test API", version="1.0.0") # Get public directory public_dir = Path(__file__).parent / "public" @app.get("/", response_class=HTMLResponse) async def root(): """Serve main HTML page with cache-busting""" try: index_path = public_dir / "index.html" async with aiofiles.open(index_path, 'r', encoding='utf8') as f: html = await f.read() # Add timestamp for cache busting timestamp = int(datetime.now().timestamp() * 1000) html = html.replace('dist/script.js?v=2', f'dist/script.js?v={timestamp}') return HTMLResponse( content=html, headers={ 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0' } ) except Exception as e: raise HTTPException(status_code=500, detail=f"Failed to serve index: {str(e)}") @app.get("/style.css") async def get_css(): """Serve CSS file""" css_path = public_dir / "style.css" if css_path.exists(): return FileResponse( path=css_path, media_type="text/css", headers={"Cache-Control": "no-cache, max-age=0"} ) raise HTTPException(status_code=404, detail="CSS not found") @app.get("/dist/script.js") async def get_js(): """Serve JavaScript file""" js_path = public_dir / "dist" / "script.js" if js_path.exists(): return FileResponse( path=js_path, media_type="application/javascript", headers={"Cache-Control": "no-cache, max-age=0"} ) raise HTTPException(status_code=404, detail="JavaScript not found") @app.get("/health") async def health_check(): """Health check endpoint""" return { "status": "ok", "timestamp": datetime.now().isoformat(), "message": "Test server running" } if __name__ == "__main__": import uvicorn port = int(os.getenv("PORT", 8000)) print(f"🚀 Starting test server on http://localhost:{port}") print(f"📁 Public directory: {public_dir.absolute()}") uvicorn.run(app, host="0.0.0.0", port=port, log_level="info")