44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
from fastapi import FastAPI, HTTPException, Request
|
|
from fastapi.responses import JSONResponse
|
|
from starlette.middleware.cors import CORSMiddleware
|
|
|
|
from app.routers import (
|
|
auth_router,
|
|
business_types_router,
|
|
plans_router,
|
|
subscriptions_router,
|
|
tenants_router,
|
|
users_router,
|
|
)
|
|
|
|
app = FastAPI(title="Profitra API", version="1.0.0")
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
@app.exception_handler(HTTPException)
|
|
async def http_exception_handler(request: Request, exc: HTTPException):
|
|
if isinstance(exc.detail, dict):
|
|
return JSONResponse(status_code=exc.status_code, content=exc.detail)
|
|
return JSONResponse(status_code=exc.status_code, content={"message": exc.detail})
|
|
|
|
|
|
API_PREFIX = "/v1"
|
|
|
|
app.include_router(auth_router, prefix=API_PREFIX)
|
|
app.include_router(business_types_router, prefix=API_PREFIX)
|
|
app.include_router(plans_router, prefix=API_PREFIX)
|
|
app.include_router(tenants_router, prefix=API_PREFIX)
|
|
app.include_router(subscriptions_router, prefix=API_PREFIX)
|
|
app.include_router(users_router, prefix=API_PREFIX)
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "Profitra API"}
|