29 lines
815 B
Python
29 lines
815 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from app.api.login import router as login_router
|
|
from app.api.submit_record import router as submit_record_router
|
|
from app.api.db import Base, engine
|
|
from app.settings import API_V1_STR
|
|
|
|
# 创建数据库表
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI(
|
|
title="PBMDB API",
|
|
description="微生物数据库后端API",
|
|
version="1.0.0"
|
|
)
|
|
|
|
# 配置CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # 在生产环境中应该设置具体的前端域名
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# 包含路由
|
|
app.include_router(login_router, prefix=API_V1_STR, tags=["login"])
|
|
app.include_router(submit_record_router, prefix=API_V1_STR, tags=["submit_record"])
|