-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
62 lines (53 loc) · 1.59 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import logging
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from config import Config
from app.api.endpoints import stock
from dotenv import load_dotenv
load_dotenv()
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
app = FastAPI(
title="Stock Analysis API",
description="API for real-time stock analysis using multi-agent system",
version="1.0.0"
)
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allows all origins
allow_credentials=True,
allow_methods=["*"], # Allows all methods
allow_headers=["*"], # Allows all headers
)
@app.on_event("startup")
async def startup_event():
try:
logger.info("Initializing application...")
config = Config()
config.setup_environment()
logger.info("Successfully initialized application")
except Exception as e:
logger.error(f"Failed to initialize application: {str(e)}")
raise
@app.get("/")
async def root():
"""Root endpoint that redirects to docs"""
return {
"message": "Welcome to Stock Analysis API",
"documentation": "/docs",
"openapi": "/openapi.json"
}
# Include routers
app.include_router(stock.router, prefix="/api/v1", tags=["stocks"])
if __name__ == "__main__":
import uvicorn
try:
uvicorn.run(app, host="0.0.0.0", port=8000)
except Exception as e:
logger.error(f"Failed to start server: {str(e)}")
raise