destinyebuka commited on
Commit
dfd3a90
·
1 Parent(s): c1c44f0
Files changed (1) hide show
  1. main.py +17 -15
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
- cors_origins = [
220
- "https://lojiz.onrender.com",
221
- "https://lojiz.com",
222
- "https://www.lojiz.com",
223
- ] if is_production else [
224
- "http://localhost",
225
- "http://localhost:3000",
226
- "http://localhost:5173",
227
- "http://localhost:8080", # Test UI
228
- "http://127.0.0.1",
229
- "http://127.0.0.1:3000",
230
- "http://127.0.0.1:5173",
231
- "http://127.0.0.1:8080", # Test UI
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=["*"],