Fix linting
Browse files
lightrag/api/lightrag_server.py
CHANGED
@@ -479,24 +479,30 @@ def create_app(args):
|
|
479 |
raise HTTPException(status_code=500, detail=str(e))
|
480 |
|
481 |
# Custom StaticFiles class for smart caching
|
482 |
-
class SmartStaticFiles(StaticFiles):
|
483 |
async def get_response(self, path: str, scope):
|
484 |
response = await super().get_response(path, scope)
|
485 |
-
|
486 |
if path.endswith(".html"):
|
487 |
-
response.headers["Cache-Control"] =
|
|
|
|
|
488 |
response.headers["Pragma"] = "no-cache"
|
489 |
response.headers["Expires"] = "0"
|
490 |
-
elif
|
491 |
-
|
|
|
|
|
|
|
|
|
492 |
# Add other rules here if needed for non-HTML, non-asset files
|
493 |
-
|
494 |
# Ensure correct Content-Type
|
495 |
if path.endswith(".js"):
|
496 |
response.headers["Content-Type"] = "application/javascript"
|
497 |
elif path.endswith(".css"):
|
498 |
response.headers["Content-Type"] = "text/css"
|
499 |
-
|
500 |
return response
|
501 |
|
502 |
# Webui mount webui/index.html
|
@@ -504,7 +510,9 @@ def create_app(args):
|
|
504 |
static_dir.mkdir(exist_ok=True)
|
505 |
app.mount(
|
506 |
"/webui",
|
507 |
-
SmartStaticFiles(
|
|
|
|
|
508 |
name="webui",
|
509 |
)
|
510 |
|
|
|
479 |
raise HTTPException(status_code=500, detail=str(e))
|
480 |
|
481 |
# Custom StaticFiles class for smart caching
|
482 |
+
class SmartStaticFiles(StaticFiles): # Renamed from NoCacheStaticFiles
|
483 |
async def get_response(self, path: str, scope):
|
484 |
response = await super().get_response(path, scope)
|
485 |
+
|
486 |
if path.endswith(".html"):
|
487 |
+
response.headers["Cache-Control"] = (
|
488 |
+
"no-cache, no-store, must-revalidate"
|
489 |
+
)
|
490 |
response.headers["Pragma"] = "no-cache"
|
491 |
response.headers["Expires"] = "0"
|
492 |
+
elif (
|
493 |
+
"/assets/" in path
|
494 |
+
): # Assets (JS, CSS, images, fonts) generated by Vite with hash in filename
|
495 |
+
response.headers["Cache-Control"] = (
|
496 |
+
"public, max-age=31536000, immutable"
|
497 |
+
)
|
498 |
# Add other rules here if needed for non-HTML, non-asset files
|
499 |
+
|
500 |
# Ensure correct Content-Type
|
501 |
if path.endswith(".js"):
|
502 |
response.headers["Content-Type"] = "application/javascript"
|
503 |
elif path.endswith(".css"):
|
504 |
response.headers["Content-Type"] = "text/css"
|
505 |
+
|
506 |
return response
|
507 |
|
508 |
# Webui mount webui/index.html
|
|
|
510 |
static_dir.mkdir(exist_ok=True)
|
511 |
app.mount(
|
512 |
"/webui",
|
513 |
+
SmartStaticFiles(
|
514 |
+
directory=static_dir, html=True, check_dir=True
|
515 |
+
), # Use SmartStaticFiles
|
516 |
name="webui",
|
517 |
)
|
518 |
|