32 lines
796 B
Python
32 lines
796 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from contextlib import asynccontextmanager
|
|
from dotenv import load_dotenv
|
|
|
|
from database import init_db
|
|
from routes import stock, collections, shares, sectors
|
|
|
|
load_dotenv()
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
init_db()
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="A股走势追踪 API", version="1.0.0", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(stock.router, prefix="/api/stock")
|
|
app.include_router(collections.router, prefix="/api/collections")
|
|
app.include_router(shares.router, prefix="/api/share")
|
|
app.include_router(sectors.router, prefix="/api/sectors")
|