Skip to content

Commit 3b1871d

Browse files
author
kevin.zhang
committed
feat: enable cors to allow play video through mounted videos url
1 parent 6a9fe08 commit 3b1871d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

app/asgi.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
"""Application implementation - ASGI."""
2+
import os
23

34
from fastapi import FastAPI, Request
45
from fastapi.exceptions import RequestValidationError
56
from fastapi.responses import JSONResponse
67
from loguru import logger
78
from fastapi.staticfiles import StaticFiles
9+
from fastapi.middleware.cors import CORSMiddleware
810

911
from app.config import config
1012
from app.models.exception import HttpException
@@ -47,6 +49,17 @@ def get_application() -> FastAPI:
4749

4850
app = get_application()
4951

52+
# Configures the CORS middleware for the FastAPI app
53+
cors_allowed_origins_str = os.getenv("CORS_ALLOWED_ORIGINS", "")
54+
origins = cors_allowed_origins_str.split(",") if cors_allowed_origins_str else ["*"]
55+
app.add_middleware(
56+
CORSMiddleware,
57+
allow_origins=origins,
58+
allow_credentials=True,
59+
allow_methods=["*"],
60+
allow_headers=["*"],
61+
)
62+
5063
task_dir = utils.task_dir()
5164
app.mount("/tasks", StaticFiles(directory=task_dir, html=True, follow_symlink=True), name="")
5265

0 commit comments

Comments
 (0)