File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
src/solace_ai_connector_web/backend Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change 33from flask_cors import CORS
44from solace_ai_connector .components .component_base import ComponentBase
55from flask_wtf import CSRFProtect
6+ from urllib .parse import urlparse
67import os
78
89info = {
@@ -216,13 +217,24 @@ def init_app(self):
216217 self .app .config ['SECRET_KEY' ] = self .csrf_key
217218 csrf .init_app (self .app )
218219
220+ frontend_origins = [self .frontend_url ]
221+
222+ # if frontend_url is using localhost or 127.0.0.1, then add them both to cors origins
223+ if "localhost" in self .frontend_url or "127.0.0.1" in self .frontend_url :
224+ parsed_url = urlparse (self .frontend_url )
225+ scheme = parsed_url .scheme
226+ port = f":{ parsed_url .port } " if parsed_url .port else ""
227+
228+ if "localhost" in self .frontend_url :
229+ frontend_origins .append (f"{ scheme } ://127.0.0.1{ port } " )
230+ else :
231+ frontend_origins .append (f"{ scheme } ://localhost{ port } " )
232+
219233 CORS (
220234 self .app ,
221235 resources = {
222236 r"/*" : {
223- "origins" : [
224- self .frontend_url ,
225- ],
237+ "origins" : frontend_origins ,
226238 "supports_credentials" : True
227239 },
228240 },
You can’t perform that action at this time.
0 commit comments