| #!/usr/bin/env python3 | |
| """ | |
| Static file server for serving HTML templates | |
| """ | |
| import os | |
| from fastapi import FastAPI | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.responses import HTMLResponse | |
| # Create a separate app for static files | |
| static_app = FastAPI() | |
| # Create templates directory if it doesn't exist | |
| os.makedirs("templates", exist_ok=True) | |
| # Mount static files | |
| static_app.mount("/templates", StaticFiles(directory="templates"), name="templates") | |
| # Serve index.html at root | |
| if os.path.exists("templates/index.html"): | |
| async def read_index(): | |
| with open("templates/index.html", "r", encoding="utf-8") as f: | |
| return f.read() | |
| else: | |
| async def read_index(): | |
| return """ | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Enhanced DOCX to PDF Converter</title> | |
| </head> | |
| <body> | |
| <h1>Enhanced DOCX to PDF Converter</h1> | |
| <p>API is running. Visit <a href="/docs">/docs</a> for API documentation.</p> | |
| </body> | |
| </html> | |
| """ |