Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

feat: enable cors to allow play video through mounted videos url

kevin.zhang3b1871d59187
diff --git a/app/asgi.py b/app/asgi.py
index 440e4c08..d21a7244 100644
--- a/app/asgi.py
+++ b/app/asgi.py
@@ -1,10 +1,12 @@
"""Application implementation - ASGI."""
+import os
from fastapi import FastAPI, Request
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
from loguru import logger
from fastapi.staticfiles import StaticFiles
+from fastapi.middleware.cors import CORSMiddleware
from app.config import config
from app.models.exception import HttpException
@@ -47,6 +49,17 @@ def get_application() -> FastAPI:
app = get_application()
+# Configures the CORS middleware for the FastAPI app
+cors_allowed_origins_str = os.getenv("CORS_ALLOWED_ORIGINS", "")
+origins = cors_allowed_origins_str.split(",") if cors_allowed_origins_str else ["*"]
+app.add_middleware(
+ CORSMiddleware,
+ allow_origins=origins,
+ allow_credentials=True,
+ allow_methods=["*"],
+ allow_headers=["*"],
+)
+
task_dir = utils.task_dir()
app.mount("/tasks", StaticFiles(directory=task_dir, html=True, follow_symlink=True), name="")