36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
import sys
|
|
import os
|
|
from fastapi import FastAPI
|
|
from starlette.middleware.cors import CORSMiddleware
|
|
|
|
# Add project root to path to allow importing tradingagents
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..")))
|
|
|
|
from app.api.router import api_router
|
|
from app.core.config import settings
|
|
from app.infrastructure.database import engine
|
|
from sqlmodel import SQLModel
|
|
|
|
def create_tables():
|
|
SQLModel.metadata.create_all(engine)
|
|
|
|
app = FastAPI(
|
|
title=settings.PROJECT_NAME,
|
|
openapi_url=f"{settings.API_V1_STR}/openapi.json"
|
|
)
|
|
|
|
@app.on_event("startup")
|
|
def on_startup():
|
|
create_tables()
|
|
|
|
# Set all CORS enabled origins
|
|
if settings.CORS_ALLOWED_ORIGINS:
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=[str(origin) for origin in settings.CORS_ALLOWED_ORIGINS],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(api_router, prefix=settings.API_V1_STR) |