migrating vendor frontend to new architecture

This commit is contained in:
2025-10-31 20:51:30 +01:00
parent 9420483ae6
commit 9611c03a36
25 changed files with 1618 additions and 286 deletions

61
main.py
View File

@@ -1,11 +1,19 @@
# main.py
import sys
import io
# Fix Windows console encoding issues (must be at the very top)
if sys.platform == 'win32':
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
import logging
from datetime import datetime, timezone
from pathlib import Path
from fastapi import Depends, FastAPI, HTTPException, Request
from fastapi import Depends, FastAPI, HTTPException, Request, Response
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import HTMLResponse, RedirectResponse
from fastapi.responses import HTMLResponse, RedirectResponse, FileResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from sqlalchemy import text
@@ -73,10 +81,49 @@ else:
# Include API router (JSON endpoints at /api/*)
app.include_router(api_router, prefix="/api")
# ============================================================================
# FAVICON ROUTES (Must be registered BEFORE page routers)
# ============================================================================
# OLD: Keep frontend router for now (we'll phase it out)
# app.include_router(frontend_router)
def serve_favicon() -> Response:
"""
Serve favicon with caching headers.
Checks multiple possible locations for the favicon.
"""
# Possible favicon locations (in priority order)
possible_paths = [
STATIC_DIR / "favicon.ico",
STATIC_DIR / "images" / "favicon.ico",
STATIC_DIR / "assets" / "favicon.ico",
]
# Find first existing favicon
for favicon_path in possible_paths:
if favicon_path.exists():
return FileResponse(
favicon_path,
media_type="image/x-icon",
headers={
"Cache-Control": "public, max-age=86400", # Cache for 1 day
}
)
# No favicon found - return 204 No Content
return Response(status_code=204)
@app.get("/favicon.ico", include_in_schema=False)
async def favicon():
"""Serve favicon from root path."""
return serve_favicon()
@app.get("/vendor/favicon.ico", include_in_schema=False)
async def vendor_favicon():
"""Handle vendor-prefixed favicon requests."""
return serve_favicon()
# ============================================================================
# HTML PAGE ROUTES (Jinja2 Templates)
@@ -93,6 +140,7 @@ app.include_router(
# Vendor pages
app.include_router(
vendor_pages.router,
prefix="/vendor",
tags=["vendor-pages"],
include_in_schema=False # Don't show HTML pages in API docs
)
@@ -100,10 +148,12 @@ app.include_router(
# Shop pages
app.include_router(
shop_pages.router,
prefix="/shop",
tags=["shop-pages"],
include_in_schema=False # Don't show HTML pages in API docs
)
# ============================================================================
# API ROUTES (JSON Responses)
# ============================================================================
@@ -163,4 +213,5 @@ async def documentation():
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)