Artem Nikolaev commited on
Commit
d99c55e
·
1 Parent(s): aa619f3

Use StaticFiles for web directory

Browse files
Files changed (1) hide show
  1. backend.py +4 -19
backend.py CHANGED
@@ -35,6 +35,10 @@ app.add_middleware(
35
  allow_headers=["*"],
36
  )
37
 
 
 
 
 
38
  TEMP_DIR = "temp_uploads"
39
  os.makedirs(TEMP_DIR, exist_ok=True)
40
 
@@ -65,25 +69,6 @@ async def get_app():
65
  return HTMLResponse(content=f.read())
66
  return HTMLResponse(content="<h1>index.html not found</h1>", status_code=404)
67
 
68
- @app.get("/web/style.css")
69
- async def get_css():
70
- with open("web/style.css", "r", encoding="utf-8") as f:
71
- return HTMLResponse(content=f.read(), media_type="text/css")
72
-
73
- @app.get("/web/script.js")
74
- async def get_js():
75
- with open("web/script.js", "r", encoding="utf-8") as f:
76
- return HTMLResponse(content=f.read(), media_type="application/javascript")
77
-
78
- @app.get("/web/icons/{icon_name}")
79
- async def get_icon(icon_name: str):
80
- icon_path = os.path.join("web", "icons", icon_name)
81
- if os.path.exists(icon_path):
82
- with open(icon_path, "rb") as f:
83
- return HTMLResponse(content=f.read(), media_type="image/svg+xml")
84
- return HTMLResponse(status_code=404)
85
-
86
-
87
  @app.post("/parse-batch")
88
  async def parse_batch(request: Request):
89
  print("\n" + "="*60)
 
35
  allow_headers=["*"],
36
  )
37
 
38
+ from fastapi.staticfiles import StaticFiles
39
+
40
+ app.mount("/web", StaticFiles(directory="web"), name="web")
41
+
42
  TEMP_DIR = "temp_uploads"
43
  os.makedirs(TEMP_DIR, exist_ok=True)
44
 
 
69
  return HTMLResponse(content=f.read())
70
  return HTMLResponse(content="<h1>index.html not found</h1>", status_code=404)
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  @app.post("/parse-batch")
73
  async def parse_batch(request: Request):
74
  print("\n" + "="*60)