Working state before icon/utils fixes - Oct 22
This commit is contained in:
27
main.py
27
main.py
@@ -3,15 +3,17 @@ import logging
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import Depends, FastAPI, HTTPException
|
||||
from fastapi import Depends, FastAPI, HTTPException, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.main import api_router
|
||||
from app.routes.frontend import router as frontend_router
|
||||
from app.routes.frontend import router as frontend_router # We'll phase this out
|
||||
from app.api.v1.admin import pages as admin_pages
|
||||
from app.core.config import settings
|
||||
from app.core.database import get_db
|
||||
from app.core.lifespan import lifespan
|
||||
@@ -24,6 +26,7 @@ logger = logging.getLogger(__name__)
|
||||
# Get the project root directory (where main.py is located)
|
||||
BASE_DIR = Path(__file__).resolve().parent
|
||||
STATIC_DIR = BASE_DIR / "static"
|
||||
TEMPLATES_DIR = BASE_DIR / "app" / "templates"
|
||||
|
||||
# FastAPI app with lifespan
|
||||
app = FastAPI(
|
||||
@@ -33,6 +36,9 @@ app = FastAPI(
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
||||
# Configure Jinja2 Templates
|
||||
templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
|
||||
|
||||
# Setup custom exception handlers (unified approach)
|
||||
setup_exception_handlers(app)
|
||||
|
||||
@@ -45,7 +51,7 @@ app.add_middleware(
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# Add vendor context middleware (ADDED - must be after CORS)
|
||||
# Add vendor context middleware (must be after CORS)
|
||||
app.middleware("http")(vendor_context_middleware)
|
||||
|
||||
# ========================================
|
||||
@@ -57,8 +63,21 @@ else:
|
||||
logger.warning(f"Static directory not found at {STATIC_DIR}")
|
||||
# ========================================
|
||||
|
||||
# Include API router
|
||||
# Include API router (JSON endpoints at /api/*)
|
||||
app.include_router(api_router, prefix="/api")
|
||||
|
||||
# ============================================================================
|
||||
# Include HTML page routes (Jinja2 templates at /admin/*)
|
||||
# ============================================================================
|
||||
app.include_router(
|
||||
admin_pages.router,
|
||||
prefix="/admin",
|
||||
tags=["admin-pages"],
|
||||
include_in_schema=False # Don't show HTML pages in API docs
|
||||
)
|
||||
# ============================================================================
|
||||
|
||||
# OLD: Keep frontend router for now (we'll phase it out)
|
||||
app.include_router(frontend_router)
|
||||
|
||||
# Public Routes (no authentication required)
|
||||
|
||||
Reference in New Issue
Block a user