from fastapi import FastAPI from starlette.middleware.sessions import SessionMiddleware from config.settings import SECRET_KEY, validate_config def create_app() -> FastAPI: """Create and configure FastAPI application""" app = FastAPI(title="Web Pedidos Klein - FastAPI Backend") # Add SessionMiddleware app.add_middleware( SessionMiddleware, secret_key=SECRET_KEY, max_age=60 * 60 # max_age in seconds for Starlette ) return app def setup_routes(app: FastAPI): """Setup all application routes""" from routes import chat, users, products, orders, static from fastapi import Depends from auth.security import protect_chat_api # Chat routes app.add_api_route("/api/chat/init-chat", chat.init_chat, methods=["GET"], summary="Initialize chat and get anti-abuse token") app.add_api_route("/api/chat/completions", chat.chat_completions, methods=["POST"], summary="Get chat completions from OpenAI", dependencies=[Depends(protect_chat_api)]) # User routes app.add_api_route("/api/existsUser", users.exists_user, methods=["POST"], summary="Check if user exists") # Product routes app.add_api_route("/api/get_products", products.get_products, methods=["GET"], summary="Get products") # Order routes app.add_api_route("/api/printer/order", orders.printer_order, methods=["POST"], summary="Printer order", dependencies=[Depends(protect_chat_api)]) # Static routes from fastapi.responses import HTMLResponse app.add_api_route("/", static.serve_index_html, methods=["GET"], response_class=HTMLResponse, include_in_schema=False) # Mount static files static.mount_static_files(app)