60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
"""Main FastAPI application"""
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.openapi.utils import get_openapi
|
|
|
|
from app.core.config import get_settings
|
|
from app.core.database import engine
|
|
from app.models.base import Base
|
|
from app.routers import auth
|
|
|
|
# Create tables
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
# Initialize FastAPI
|
|
settings = get_settings()
|
|
app = FastAPI(
|
|
title=settings.app_name,
|
|
version=settings.app_version,
|
|
openapi_url=f"{settings.api_prefix}/openapi.json",
|
|
docs_url=f"{settings.api_prefix}/docs",
|
|
)
|
|
|
|
# CORS middleware (adjust origins for production)
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://localhost:3000", "http://localhost:5173"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(auth.router, prefix=settings.api_prefix)
|
|
|
|
# Health check
|
|
@app.get("/health")
|
|
def health_check():
|
|
"""Health check endpoint"""
|
|
return {"status": "ok", "service": settings.app_name}
|
|
|
|
|
|
# OpenAPI customization
|
|
def custom_openapi():
|
|
"""Customize OpenAPI schema"""
|
|
if app.openapi_schema:
|
|
return app.openapi_schema
|
|
|
|
openapi_schema = get_openapi(
|
|
title=settings.app_name,
|
|
version=settings.app_version,
|
|
description="Cisco Config Builder SaaS - Network device configuration management",
|
|
routes=app.routes,
|
|
)
|
|
|
|
app.openapi_schema = openapi_schema
|
|
return app.openapi_schema
|
|
|
|
|
|
app.openapi = custom_openapi
|