28 lines
761 B
Python
28 lines
761 B
Python
import uvicorn
|
|
from fastapi import FastAPI
|
|
|
|
from core.config import settings
|
|
from starlette.middleware.cors import CORSMiddleware
|
|
|
|
from db import connect_to_mongo, close_mongo_connection
|
|
|
|
app = FastAPI(title=settings.PROJECT_NAME)
|
|
|
|
if settings.BACKEND_CORS_ORIGINS:
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=['*'],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
app.add_event_handler("startup", connect_to_mongo)
|
|
app.add_event_handler("shutdown", close_mongo_connection)
|
|
|
|
from api.api_v1.api import api_router
|
|
|
|
app.include_router(api_router, prefix=settings.API_V1_STR)
|
|
|
|
if __name__ == '__main__':
|
|
uvicorn.run(app='main:app', host="127.0.0.1", port=8889, reload=True, debug=True)
|