Harmonize navigation and modals across cookbook & shopping list, fix WebSocket proxying, and add PWA offline support
This commit is contained in:
+21
-2
@@ -10,7 +10,7 @@ from typing import List, Optional, Dict, Any
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI, HTTPException, Request, Query, Form, File, UploadFile, WebSocket, WebSocketDisconnect
|
||||
from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse
|
||||
from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse, FileResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from datetime import datetime, date, timedelta
|
||||
@@ -70,7 +70,7 @@ APP_USERNAME = os.getenv("APP_USERNAME", "admin")
|
||||
APP_PASSWORD = os.getenv("APP_PASSWORD", "wtc2026!")
|
||||
SECRET_KEY = os.getenv("SECRET_KEY", "wtc_cookbook_secret_salt_2026_supersecure")
|
||||
COOKIE_NAME = "wtc_auth"
|
||||
PUBLIC_PATHS = {"/login", "/api/login", "/favicon.ico"}
|
||||
PUBLIC_PATHS = {"/login", "/api/login", "/favicon.ico", "/manifest.json", "/sw.js"}
|
||||
|
||||
def create_auth_token(username: str, days: int = 30) -> str:
|
||||
expiry = int(time.time()) + (days * 86400)
|
||||
@@ -224,6 +224,25 @@ class ShoppingItemCategoryUpdate(BaseModel):
|
||||
category: str
|
||||
|
||||
|
||||
# ==========================================
|
||||
# PWA MANIFEST & SERVICE WORKER
|
||||
# ==========================================
|
||||
|
||||
@app.get("/manifest.json")
|
||||
def get_manifest():
|
||||
manifest_path = os.path.join(STATIC_DIR, "manifest.json")
|
||||
if os.path.exists(manifest_path):
|
||||
return FileResponse(manifest_path, media_type="application/manifest+json")
|
||||
raise HTTPException(status_code=404, detail="Manifest not found")
|
||||
|
||||
@app.get("/sw.js")
|
||||
def get_service_worker():
|
||||
sw_path = os.path.join(STATIC_DIR, "sw.js")
|
||||
if os.path.exists(sw_path):
|
||||
return FileResponse(sw_path, media_type="application/javascript", headers={"Service-Worker-Allowed": "/"})
|
||||
raise HTTPException(status_code=404, detail="Service worker not found")
|
||||
|
||||
|
||||
# ==========================================
|
||||
# AUTH VIEWS
|
||||
# ==========================================
|
||||
|
||||
Reference in New Issue
Block a user