| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- from time import struct_time
- from fastapi import FastAPI
- from starlette.middleware.sessions import SessionMiddleware
- from config.settings import SECRET_KEY, validate_config
- from routes import sales
- def create_app() -> FastAPI:
- """Create and configure FastAPI application"""
- app = FastAPI(title="Web Pedidos Klein - FastAPI Backend",
- description="Backend for the Web Pedidos Klein application using FastAPI",)
-
- # 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 get_current_user
-
- # Chat routes
- app.include_router(chat.chat_router, prefix="/api/chat",tags=["Chat"], dependencies=[Depends(get_current_user)])
- # User routes
- app.include_router(users.user_router, prefix="/api/users", tags=["Users"])
- # Product routes
- app.include_router(products.product_router, prefix="/api/products", tags=["Products"],dependencies=[Depends(get_current_user)])
- # Order routes
- app.include_router(orders.order_router, prefix="/api/orders", tags=["Orders"], dependencies=[Depends(get_current_user)])
-
- # Sales routes
- app.include_router(sales.sales_router, prefix="/api/sales", tags=["Sales"], dependencies=[Depends(get_current_user)])
- # Verification routes
- app.include_router(users.verify_router, prefix="/verify", tags=["Verification"])
- # Static routes
- from fastapi.responses import HTMLResponse
- app.add_api_route("/", static.serve_app_html, methods=["GET"],
- response_class=HTMLResponse, include_in_schema=False)
- app.add_api_route("/register", static.serve_register_html, methods=["GET"],
- response_class=HTMLResponse, include_in_schema=False)
- # Mount static files
- static.mount_main_static_files(app)
- static.mount_register_static_files(app)
|