Skip to content

Commit 6a61ab4

Browse files
Create a list of origins to accept on CORS.
1 parent 3369964 commit 6a61ab4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Diff for: proxbox_api/proxbox_api/main.py

+25
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,31 @@ async def proxbox_tag():
100100
#netbox_url
101101
]
102102

103+
# Get all NetBox endpoints and build CORS origins list - The following code was generated by Cursor.
104+
netbox_endpoints = NetBoxEndpoint.objects.all()
105+
origins = []
106+
107+
for endpoint in netbox_endpoints:
108+
# Build protocol based on verify_ssl
109+
protocol = "https" if endpoint.verify_ssl else "http"
110+
111+
# Add both HTTP and HTTPS origins for each domain
112+
origins.extend([
113+
f"{protocol}://{endpoint.domain}",
114+
f"{protocol}://{endpoint.domain}:80",
115+
f"{protocol}://{endpoint.domain}:443",
116+
f"{protocol}://{endpoint.domain}:8000"
117+
])
118+
119+
# Add default development origins
120+
origins.extend([
121+
"https://127.0.0.1:443",
122+
"http://127.0.0.1:80",
123+
"http://127.0.0.1:8000"
124+
])
125+
126+
127+
103128
app.add_middleware(
104129
CORSMiddleware,
105130
allow_origins=['*'],

0 commit comments

Comments
 (0)