rakib72642 commited on
Commit
0102e34
·
1 Parent(s): fc967af

all fixed

Browse files
Files changed (2) hide show
  1. app.py +9 -4
  2. frontend/index.html +2 -2
app.py CHANGED
@@ -28,6 +28,7 @@ import json
28
  import os
29
  import uuid
30
  from contextlib import asynccontextmanager
 
31
 
32
  from fastapi import FastAPI, WebSocket, WebSocketDisconnect, Request
33
  from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
@@ -92,17 +93,21 @@ async def lifespan(app: FastAPI):
92
 
93
  app = FastAPI(lifespan=lifespan)
94
 
 
 
 
95
  try:
96
- app.mount("/static", StaticFiles(directory="."), name="static")
97
  except Exception:
98
  pass
99
 
100
 
101
  @app.get("/")
102
  async def root():
103
- if os.path.exists("index.html"):
104
- return FileResponse("index.html")
105
- return HTMLResponse("<h2>index.html not found</h2>", status_code=404)
 
106
 
107
 
108
  @app.get("/health")
 
28
  import os
29
  import uuid
30
  from contextlib import asynccontextmanager
31
+ from pathlib import Path
32
 
33
  from fastapi import FastAPI, WebSocket, WebSocketDisconnect, Request
34
  from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
 
93
 
94
  app = FastAPI(lifespan=lifespan)
95
 
96
+ BASE_DIR = Path(__file__).resolve().parent
97
+ FRONTEND_DIR = BASE_DIR / "frontend"
98
+
99
  try:
100
+ app.mount("/static", StaticFiles(directory=str(FRONTEND_DIR)), name="static")
101
  except Exception:
102
  pass
103
 
104
 
105
  @app.get("/")
106
  async def root():
107
+ index_path = FRONTEND_DIR / "index.html"
108
+ if index_path.exists():
109
+ return FileResponse(str(index_path))
110
+ return HTMLResponse("<h2>frontend/index.html not found</h2>", status_code=404)
111
 
112
 
113
  @app.get("/health")
frontend/index.html CHANGED
@@ -7,7 +7,7 @@
7
  <link rel="preconnect" href="https://fonts.googleapis.com">
8
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9
  <link href="https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=JetBrains+Mono:wght@300;400&family=Hind+Siliguri:wght@300;400;500;600&display=swap" rel="stylesheet">
10
- <link rel="stylesheet" href="style.css" />
11
  </head>
12
  <body>
13
 
@@ -261,6 +261,6 @@
261
  </div>
262
 
263
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
264
- <script src="script.js"></script>
265
  </body>
266
  </html>
 
7
  <link rel="preconnect" href="https://fonts.googleapis.com">
8
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9
  <link href="https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=JetBrains+Mono:wght@300;400&family=Hind+Siliguri:wght@300;400;500;600&display=swap" rel="stylesheet">
10
+ <link rel="stylesheet" href="/static/style.css" />
11
  </head>
12
  <body>
13
 
 
261
  </div>
262
 
263
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
264
+ <script src="/static/script.js"></script>
265
  </body>
266
  </html>