Spaces:
Sleeping
Sleeping
Nagesh Muralidhar
commited on
Commit
·
e01254e
1
Parent(s):
2784e84
addin app.py
Browse files- app.py +27 -17
- static/index.html +15 -0
app.py
CHANGED
@@ -60,15 +60,6 @@ def get_index_html():
|
|
60 |
else:
|
61 |
return "<html><body><h1>Index file not found</h1></body></html>"
|
62 |
|
63 |
-
try:
|
64 |
-
# Try to import the backend app but don't use it directly
|
65 |
-
import backend.app.main
|
66 |
-
logger.info("Backend module imported successfully")
|
67 |
-
backend_available = True
|
68 |
-
except Exception as e:
|
69 |
-
logger.error(f"Error importing backend module: {str(e)}")
|
70 |
-
backend_available = False
|
71 |
-
|
72 |
# Create the main application
|
73 |
app = FastAPI(title="PodCraft")
|
74 |
|
@@ -81,6 +72,33 @@ app.add_middleware(
|
|
81 |
allow_headers=["*"],
|
82 |
)
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
# Define the root route that directly serves index.html
|
85 |
@app.get("/", response_class=HTMLResponse)
|
86 |
async def root():
|
@@ -124,14 +142,6 @@ if static_path.exists():
|
|
124 |
# Catch-all route for client-side routing in the React app
|
125 |
@app.get("/{full_path:path}")
|
126 |
async def catch_all(full_path: str, request: Request):
|
127 |
-
# Skip API paths and redirect them to the backend
|
128 |
-
if full_path.startswith("api/") or full_path == "docs" or full_path == "openapi.json":
|
129 |
-
if backend_available:
|
130 |
-
# Use the backend.app.main module's routes
|
131 |
-
return backend.app.main.app.get(full_path)
|
132 |
-
else:
|
133 |
-
return {"error": "Backend API not available"}
|
134 |
-
|
135 |
# Skip static file paths
|
136 |
if full_path.startswith("static/") or full_path.startswith("assets/"):
|
137 |
raise HTTPException(status_code=404, detail="Not found")
|
|
|
60 |
else:
|
61 |
return "<html><body><h1>Index file not found</h1></body></html>"
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
# Create the main application
|
64 |
app = FastAPI(title="PodCraft")
|
65 |
|
|
|
72 |
allow_headers=["*"],
|
73 |
)
|
74 |
|
75 |
+
# Try to load the backend app
|
76 |
+
backend_app = None
|
77 |
+
try:
|
78 |
+
# Import the backend app
|
79 |
+
from backend.app.main import app as backend_app
|
80 |
+
logger.info("Backend module imported successfully")
|
81 |
+
|
82 |
+
# Add all non-root routes from the backend app to our main app
|
83 |
+
from fastapi.routing import APIRoute, APIRouter
|
84 |
+
|
85 |
+
# Create a router for backend routes
|
86 |
+
backend_router = APIRouter()
|
87 |
+
|
88 |
+
# Add all routes from the backend app to our router
|
89 |
+
for route in backend_app.routes:
|
90 |
+
if not (isinstance(route, APIRoute) and route.path == "/"):
|
91 |
+
# Add this route to our router
|
92 |
+
logger.info(f"Adding backend route: {route.path}")
|
93 |
+
backend_router.routes.append(route)
|
94 |
+
|
95 |
+
# Include the backend router in our main app
|
96 |
+
app.include_router(backend_router)
|
97 |
+
|
98 |
+
except Exception as e:
|
99 |
+
logger.error(f"Error importing backend module: {str(e)}")
|
100 |
+
backend_app = None
|
101 |
+
|
102 |
# Define the root route that directly serves index.html
|
103 |
@app.get("/", response_class=HTMLResponse)
|
104 |
async def root():
|
|
|
142 |
# Catch-all route for client-side routing in the React app
|
143 |
@app.get("/{full_path:path}")
|
144 |
async def catch_all(full_path: str, request: Request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
# Skip static file paths
|
146 |
if full_path.startswith("static/") or full_path.startswith("assets/"):
|
147 |
raise HTTPException(status_code=404, detail="Not found")
|
static/index.html
CHANGED
@@ -2,8 +2,23 @@
|
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
|
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>PodCraft - AI Podcast Generator</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" />
|
8 |
<style>
|
9 |
body {
|
|
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
<title>PodCraft - AI Podcast Generator</title>
|
8 |
+
<script type="text/javascript">
|
9 |
+
// Set the API base URL dynamically based on the current domain
|
10 |
+
window.API_BASE_URL = ''; // Empty string means use current domain
|
11 |
+
|
12 |
+
// Override fetch to rewrite localhost:8000 URLs
|
13 |
+
const originalFetch = window.fetch;
|
14 |
+
window.fetch = function(url, options) {
|
15 |
+
if (typeof url === 'string' && url.includes('localhost:8000')) {
|
16 |
+
// Replace localhost:8000 with current origin (empty string)
|
17 |
+
url = url.replace('http://localhost:8000', '');
|
18 |
+
}
|
19 |
+
return originalFetch.call(this, url, options);
|
20 |
+
};
|
21 |
+
</script>
|
22 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" />
|
23 |
<style>
|
24 |
body {
|