Skip to content

Commit

Permalink
fix socketio cors authentication for object detection and qa metrics …
Browse files Browse the repository at this point in the history
…requests
  • Loading branch information
imatiach-msft committed Dec 13, 2023
1 parent 6afef2e commit c87cda2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion apps/widget/src/app/callFlaskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export async function connectToFlaskService<TRequest, TResponse>(
}
const url = config.baseUrl;
const socket = io(url, {
reconnectionDelayMax: 10000
reconnectionDelayMax: 10000,
withCredentials: config.withCredentials
});
socket.on("connect", () => {
console.log(`socket connected, socket id: ${socket.id}, url: ${url}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ def __init__(self, service):
self.successfully_detected = True
self.nbvm_origins = [
f"https://{instance_name}.{domain_suffix}",
f"https://{instance_name}-{service.port}.{domain_suffix}"
f"https://{instance_name}-{service.port}.{domain_suffix}",
f"wss://{instance_name}.{domain_suffix}",
f"wss://{instance_name}-{service.port}.{domain_suffix}",
"https://ml.azure.com",
"https://dev.ml.azure.com",
"https://int.ml.azure.com"
]

def get_nbvm_config(self):
Expand Down
6 changes: 5 additions & 1 deletion rai_core_flask/rai_core_flask/flask_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def __init__(self, ip=None, port=None, with_credentials=False):
self.with_credentials = with_credentials
# dictionary to store arbitrary state for use by consuming classes
self.shared_state = {}
self.socketio = SocketIO(self.app)
if self.ip is None:
self.ip = "localhost"
if self.port is None:
Expand All @@ -57,6 +56,11 @@ def __init__(self, ip=None, port=None, with_credentials=False):
FlaskHelper._is_local_port_available(self.ip, self.port,
raise_error=True)
self.env = build_environment(self)
if hasattr(self.env, 'nbvm_origins'):
self.socketio = SocketIO(
self.app, cors_allowed_origins=self.env.nbvm_origins)
else:
self.socketio = SocketIO(self.app)
if self.env.base_url is None:
return
# Sleep for 1 second in order to prevent random errors while
Expand Down

0 comments on commit c87cda2

Please sign in to comment.