mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-02-02 18:22:39 +08:00
32 lines
695 B
Python
32 lines
695 B
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.core.config import settings
|
|
from app.startup.lifecycle import lifespan
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
"""
|
|
创建并配置 FastAPI 应用实例。
|
|
"""
|
|
_app = FastAPI(
|
|
title=settings.PROJECT_NAME,
|
|
openapi_url=f"{settings.API_V1_STR}/openapi.json",
|
|
lifespan=lifespan
|
|
)
|
|
|
|
# 配置 CORS 中间件
|
|
_app.add_middleware(
|
|
CORSMiddleware, # noqa
|
|
allow_origins=settings.ALLOWED_HOSTS,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
return _app
|
|
|
|
|
|
# 创建 FastAPI 应用实例
|
|
app = create_app()
|