37 lines
925 B
Python
37 lines
925 B
Python
from contextlib import asynccontextmanager
|
|
from pathlib import Path
|
|
from fastapi import FastAPI
|
|
from jinja2 import Environment, FileSystemLoader
|
|
from app.database import engine, Base
|
|
from app.seed import seed
|
|
from app.routers import contracts, analysis, data_input, admin
|
|
|
|
TEMPLATES_DIR = Path(__file__).parent / "templates"
|
|
|
|
|
|
def setup_jinja(app: FastAPI):
|
|
env = Environment(loader=FileSystemLoader(str(TEMPLATES_DIR)))
|
|
app.state.templates = env
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
setup_jinja(app)
|
|
Base.metadata.create_all(bind=engine)
|
|
seed()
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="期货量化系统", lifespan=lifespan)
|
|
|
|
app.include_router(contracts.router)
|
|
app.include_router(analysis.router)
|
|
app.include_router(data_input.router)
|
|
app.include_router(admin.router)
|
|
|
|
|
|
@app.get("/")
|
|
def root():
|
|
from fastapi.responses import RedirectResponse
|
|
return RedirectResponse("/contracts")
|