cloud450 commited on
Commit
0275f08
·
verified ·
1 Parent(s): 20befc7

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +13 -3
main.py CHANGED
@@ -6,6 +6,7 @@ import os
6
 
7
  # Load environment variables
8
  load_dotenv()
 
9
 
10
  app = FastAPI(
11
  title="Network IDS API",
@@ -14,10 +15,19 @@ app = FastAPI(
14
  root_path=os.getenv("ROOT_PATH", "")
15
  )
16
 
17
- # Allow Streamlit frontend
 
 
 
 
 
 
 
 
 
18
  app.add_middleware(
19
  CORSMiddleware,
20
- allow_origins=["*"],
21
  allow_credentials=True,
22
  allow_methods=["*"],
23
  allow_headers=["*"],
@@ -33,4 +43,4 @@ app.include_router(blockchain.router, prefix="/blockchain", tags=["Blockchain"])
33
 
34
  @app.get("/")
35
  def home():
36
- return {"message": "Network IDS Backend Running!"}
 
6
 
7
  # Load environment variables
8
  load_dotenv()
9
+ # Trigger reload
10
 
11
  app = FastAPI(
12
  title="Network IDS API",
 
15
  root_path=os.getenv("ROOT_PATH", "")
16
  )
17
 
18
+ # Configure CORS
19
+ # Default to ["*"] if not set. To restrict, set ALLOWED_ORIGINS="http://localhost:3000,https://my-app.hf.space"
20
+ origins_env = os.getenv("ALLOWED_ORIGINS", "*")
21
+ if origins_env == "*":
22
+ origins = ["*"]
23
+ else:
24
+ origins = [origin.strip() for origin in origins_env.split(",") if origin.strip()]
25
+
26
+ print(f"Allowed CORS Origins: {origins}")
27
+
28
  app.add_middleware(
29
  CORSMiddleware,
30
+ allow_origins=origins,
31
  allow_credentials=True,
32
  allow_methods=["*"],
33
  allow_headers=["*"],
 
43
 
44
  @app.get("/")
45
  def home():
46
+ return {"message": "Network IDS Backend Running!"}