Files
auv/backend/main.py
T
SakurasanandClaude 45836f4a30 feat: 新增题材页面(列表 + 详情)
- 主页增加「题材热点」入口,跳转题材列表页
- 题材列表页:展示全部题材,支持按涨幅/强度/热度/成交额排序
- 题材详情页:简介、热点事件、相关新闻、板块涨跌统计、全部相关股票(含入选理由默认展开)
- 后端逆向封装东方财富题材接口 getThemeList/getDetail/getStockList,含交易时段感知缓存

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-06 17:22:04 +08:00

50 lines
1.7 KiB
Python

import os
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse, JSONResponse
from contextlib import asynccontextmanager
from dotenv import load_dotenv
from database import init_db
from routes import stock, collections, shares, sectors, themes
load_dotenv()
@asynccontextmanager
async def lifespan(app: FastAPI):
init_db()
yield
app = FastAPI(title="AUV 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")
app.include_router(themes.router, prefix="/api/themes")
# 生产模式:后端同时托管前端静态文件
# catch-all 路由在 API 路由之后注册,所以 API 优先级更高
dist_path = os.path.join(os.path.dirname(__file__), "dist")
if os.path.isdir(dist_path):
@app.get("/{full_path:path}")
async def serve_spa(full_path: str):
file_path = os.path.join(dist_path, full_path) if full_path else os.path.join(dist_path, "index.html")
if os.path.isfile(file_path):
return FileResponse(file_path)
# SPA fallback: 非文件路径统一返回 index.html
index_path = os.path.join(dist_path, "index.html")
if os.path.isfile(index_path):
return FileResponse(index_path, media_type="text/html")
return JSONResponse({"detail": "Not Found"}, status_code=404)