Spaces:
Sleeping
Sleeping
cors error
Browse files
main.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
from __future__ import annotations
|
| 3 |
|
| 4 |
from contextlib import asynccontextmanager
|
|
|
|
| 5 |
from pathlib import Path
|
| 6 |
from typing import Any, Dict, List
|
| 7 |
|
|
@@ -98,10 +99,23 @@ async def lifespan(app: FastAPI):
|
|
| 98 |
|
| 99 |
app = FastAPI(lifespan=lifespan)
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
app.add_middleware(
|
| 102 |
CORSMiddleware,
|
| 103 |
-
allow_origins=
|
| 104 |
-
allow_credentials=
|
| 105 |
allow_methods=["*"],
|
| 106 |
allow_headers=["*"],
|
| 107 |
)
|
|
|
|
| 2 |
from __future__ import annotations
|
| 3 |
|
| 4 |
from contextlib import asynccontextmanager
|
| 5 |
+
import os
|
| 6 |
from pathlib import Path
|
| 7 |
from typing import Any, Dict, List
|
| 8 |
|
|
|
|
| 99 |
|
| 100 |
app = FastAPI(lifespan=lifespan)
|
| 101 |
|
| 102 |
+
allowed_origins_env = os.getenv("ALLOWED_ORIGINS")
|
| 103 |
+
if allowed_origins_env:
|
| 104 |
+
allowed_origins = [
|
| 105 |
+
origin.strip()
|
| 106 |
+
for origin in allowed_origins_env.split(",")
|
| 107 |
+
if origin.strip()
|
| 108 |
+
]
|
| 109 |
+
else:
|
| 110 |
+
allowed_origins = [
|
| 111 |
+
"http://localhost:5173",
|
| 112 |
+
"http://127.0.0.1:5173",
|
| 113 |
+
]
|
| 114 |
+
|
| 115 |
app.add_middleware(
|
| 116 |
CORSMiddleware,
|
| 117 |
+
allow_origins=allowed_origins,
|
| 118 |
+
allow_credentials=False,
|
| 119 |
allow_methods=["*"],
|
| 120 |
allow_headers=["*"],
|
| 121 |
)
|