File size: 1,152 Bytes
623e14e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/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"):
    @static_app.get("/", response_class=HTMLResponse)
    async def read_index():
        with open("templates/index.html", "r", encoding="utf-8") as f:
            return f.read()
else:
    @static_app.get("/", response_class=HTMLResponse)
    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>
        """