Spaces:
Running
Running
Commit
·
dfd3a90
1
Parent(s):
c1c44f0
fyp
Browse files
main.py
CHANGED
|
@@ -215,25 +215,27 @@ app.state.limiter = limiter
|
|
| 215 |
app.add_exception_handler(RateLimitExceeded, rate_limit_exceeded_handler)
|
| 216 |
app.add_middleware(SlowAPIMiddleware)
|
| 217 |
|
| 218 |
-
# CORS
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
|
|
|
| 233 |
|
| 234 |
app.add_middleware(
|
| 235 |
CORSMiddleware,
|
| 236 |
allow_origins=cors_origins,
|
|
|
|
| 237 |
allow_credentials=True,
|
| 238 |
allow_methods=["*"],
|
| 239 |
allow_headers=["*"],
|
|
|
|
| 215 |
app.add_exception_handler(RateLimitExceeded, rate_limit_exceeded_handler)
|
| 216 |
app.add_middleware(SlowAPIMiddleware)
|
| 217 |
|
| 218 |
+
# CORS - Allow all localhost ports in development
|
| 219 |
+
if is_production:
|
| 220 |
+
cors_origins = [
|
| 221 |
+
"https://lojiz.onrender.com",
|
| 222 |
+
"https://lojiz.com",
|
| 223 |
+
"https://www.lojiz.com",
|
| 224 |
+
]
|
| 225 |
+
cors_origin_regex = None
|
| 226 |
+
else:
|
| 227 |
+
# Development - allow any localhost port (Flutter uses random ports like 50421)
|
| 228 |
+
cors_origins = [
|
| 229 |
+
"http://localhost",
|
| 230 |
+
"http://127.0.0.1",
|
| 231 |
+
]
|
| 232 |
+
# Regex to match localhost with any port
|
| 233 |
+
cors_origin_regex = r"^https?://(localhost|127\.0\.0\.1)(:\d+)?$"
|
| 234 |
|
| 235 |
app.add_middleware(
|
| 236 |
CORSMiddleware,
|
| 237 |
allow_origins=cors_origins,
|
| 238 |
+
allow_origin_regex=cors_origin_regex,
|
| 239 |
allow_credentials=True,
|
| 240 |
allow_methods=["*"],
|
| 241 |
allow_headers=["*"],
|