2024-03-28 18:04:20 -05:00
|
|
|
import sentry_sdk
|
2019-02-09 19:42:36 +04:00
|
|
|
from fastapi import FastAPI
|
2023-12-26 10:51:46 -05:00
|
|
|
from fastapi.routing import APIRoute
|
2019-02-09 19:42:36 +04:00
|
|
|
from starlette.middleware.cors import CORSMiddleware
|
|
|
|
|
2024-03-02 05:01:59 -05:00
|
|
|
from app.api.main import api_router
|
2020-04-16 23:56:10 -06:00
|
|
|
from app.core.config import settings
|
2019-02-09 19:42:36 +04:00
|
|
|
|
2023-12-26 10:51:46 -05:00
|
|
|
|
2024-03-10 14:47:21 -05:00
|
|
|
def custom_generate_unique_id(route: APIRoute) -> str:
|
2023-12-26 10:51:46 -05:00
|
|
|
return f"{route.tags[0]}-{route.name}"
|
|
|
|
|
|
|
|
|
2024-04-02 22:29:32 -05:00
|
|
|
if settings.SENTRY_DSN and settings.ENVIRONMENT != "local":
|
2024-03-28 18:04:20 -05:00
|
|
|
sentry_sdk.init(dsn=str(settings.SENTRY_DSN), enable_tracing=True)
|
|
|
|
|
:recycle: Refactor backend, settings, DB sessions, types, configs, plugins (#158)
* :recycle: Refactor backend, update DB session handling
* :sparkles: Add mypy config and plugins
* :heavy_plus_sign: Use Python-jose instead of PyJWT
as it has some extra functionalities and features
* :sparkles: Add/update scripts for test, lint, format
* :wrench: Update lint and format configs
* :art: Update import format, comments, and types
* :art: Add types to config
* :sparkles: Add types for all the code, and small fixes
* :art: Use global imports to simplify exploring with Jupyter
* :recycle: Import schemas and models, instead of each class
* :truck: Rename db_session to db for simplicity
* :pushpin: Update dependencies installation for testing
2020-04-20 19:03:13 +02:00
|
|
|
app = FastAPI(
|
2023-12-26 10:51:46 -05:00
|
|
|
title=settings.PROJECT_NAME,
|
|
|
|
openapi_url=f"{settings.API_V1_STR}/openapi.json",
|
|
|
|
generate_unique_id_function=custom_generate_unique_id,
|
:recycle: Refactor backend, settings, DB sessions, types, configs, plugins (#158)
* :recycle: Refactor backend, update DB session handling
* :sparkles: Add mypy config and plugins
* :heavy_plus_sign: Use Python-jose instead of PyJWT
as it has some extra functionalities and features
* :sparkles: Add/update scripts for test, lint, format
* :wrench: Update lint and format configs
* :art: Update import format, comments, and types
* :art: Add types to config
* :sparkles: Add types for all the code, and small fixes
* :art: Use global imports to simplify exploring with Jupyter
* :recycle: Import schemas and models, instead of each class
* :truck: Rename db_session to db for simplicity
* :pushpin: Update dependencies installation for testing
2020-04-20 19:03:13 +02:00
|
|
|
)
|
2019-02-09 19:42:36 +04:00
|
|
|
|
|
|
|
# Set all CORS enabled origins
|
2020-04-16 23:56:10 -06:00
|
|
|
if settings.BACKEND_CORS_ORIGINS:
|
2019-02-09 19:42:36 +04:00
|
|
|
app.add_middleware(
|
|
|
|
CORSMiddleware,
|
2024-02-29 02:03:23 +01:00
|
|
|
allow_origins=[
|
|
|
|
str(origin).strip("/") for origin in settings.BACKEND_CORS_ORIGINS
|
|
|
|
],
|
2019-02-09 19:42:36 +04:00
|
|
|
allow_credentials=True,
|
|
|
|
allow_methods=["*"],
|
|
|
|
allow_headers=["*"],
|
:recycle: Refactor backend, settings, DB sessions, types, configs, plugins (#158)
* :recycle: Refactor backend, update DB session handling
* :sparkles: Add mypy config and plugins
* :heavy_plus_sign: Use Python-jose instead of PyJWT
as it has some extra functionalities and features
* :sparkles: Add/update scripts for test, lint, format
* :wrench: Update lint and format configs
* :art: Update import format, comments, and types
* :art: Add types to config
* :sparkles: Add types for all the code, and small fixes
* :art: Use global imports to simplify exploring with Jupyter
* :recycle: Import schemas and models, instead of each class
* :truck: Rename db_session to db for simplicity
* :pushpin: Update dependencies installation for testing
2020-04-20 19:03:13 +02:00
|
|
|
)
|
2019-02-09 19:42:36 +04:00
|
|
|
|
2020-04-16 23:56:10 -06:00
|
|
|
app.include_router(api_router, prefix=settings.API_V1_STR)
|