Files
rengine/api/app/main.py
T
Yogesh Ojha 53a50660f5 Add migration commands to README, update docker-compose for volume mounts, and enhance Target model with WhoisRecord relationship
- Added migration commands to the new dev-README.md for creating and rolling back migrations.
- Updated docker-compose.yml to include additional volume mounts for alembic and build artifacts in development and worker services.
- Enhanced Target model in target.py to include a relationship with WhoisRecord and added WhoisRecordSummary to TargetRead for better data representation.
2026-02-07 21:37:56 +05:30

86 lines
2.1 KiB
Python

from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.utils import get_openapi
from fastapi_pagination import add_pagination
from app.api.router import router as api_router
from app.config import settings
from app.core.logging import logger
from app.core.redis_listener import RedisNotificationListener
from app.utils.helpers import create_initial_admin
redis_listener = RedisNotificationListener(settings.redis_url)
@asynccontextmanager
async def lifespan(_app: FastAPI):
logger.info("Starting Backend...")
try:
await create_initial_admin()
await redis_listener.start()
except Exception as e:
logger.exception("Failed to initialize the application: %s", e)
raise e
yield
logger.info("Shutting down reNgine Backend...")
await redis_listener.stop()
app = FastAPI(
title=settings.APP_NAME,
version=settings.APP_VERSION,
lifespan=lifespan,
)
add_pagination(app)
def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title=settings.APP_NAME,
version=settings.APP_VERSION,
description="reNgine 3.0 - Attack Surface Management Platform",
routes=app.routes,
)
openapi_schema["components"]["securitySchemes"] = {
"BearerAuth": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT",
"description": "Enter your JWT token from /auth/login",
}
}
app.openapi_schema = openapi_schema
return app.openapi_schema
app.openapi = custom_openapi
app.add_middleware(
CORSMiddleware,
allow_origins=settings.CORS_ORIGINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(api_router, prefix=settings.API_V1_PREFIX)
@app.get("/")
async def root():
logger.debug("Root endpoint accessed")
return {
"message": "Welcome to reNgine API",
"version": settings.APP_VERSION,
"docs": "/docs",
}