Raymond Weitekamp commited on
Commit
8cca7aa
·
1 Parent(s): 21e190a

Fix viewer startup sequence and Nginx path handling

Browse files
Files changed (2) hide show
  1. Dockerfile +3 -3
  2. cadviewer.py +9 -4
Dockerfile CHANGED
@@ -104,9 +104,9 @@ http {\n\
104
  proxy_set_header X-Forwarded-Proto $scheme;\n\
105
  }\n\
106
  \n\
107
- # Viewer route\n\
108
- location /viewer/ {\n\
109
- proxy_pass http://viewer/viewer/;\n\
110
  proxy_http_version 1.1;\n\
111
  proxy_set_header Upgrade $http_upgrade;\n\
112
  proxy_set_header Connection $connection_upgrade;\n\
 
104
  proxy_set_header X-Forwarded-Proto $scheme;\n\
105
  }\n\
106
  \n\
107
+ # Viewer route - handle both /viewer and /viewer/ paths\n\
108
+ location ~ ^/viewer/?(.*)$ {\n\
109
+ proxy_pass http://viewer/viewer/$1;\n\
110
  proxy_http_version 1.1;\n\
111
  proxy_set_header Upgrade $http_upgrade;\n\
112
  proxy_set_header Connection $connection_upgrade;\n\
cadviewer.py CHANGED
@@ -67,11 +67,15 @@ editor_fontsize = 18
67
  # Global variables to track viewer and connection state
68
  viewer_initialized = False
69
  viewer_ready = False
 
70
 
71
- # run ocp_vscode in a subprocess
72
  def startup_all():
73
  global ocpcv_proc, viewer_initialized
74
  try:
 
 
 
 
75
  logger.info("Starting ocp_vscode subprocess")
76
  # spawn separate viewer process
77
  env = os.environ.copy() # Copy current environment
@@ -101,8 +105,8 @@ def check_viewer_ready():
101
  """Check if the viewer is ready by attempting a test connection"""
102
  try:
103
  import requests
104
- # Check the viewer through Nginx proxy
105
- response = requests.get('http://localhost:7860/viewer/')
106
  return response.status_code == 200
107
  except Exception as e:
108
  logger.error(f"Error checking viewer: {str(e)}")
@@ -231,6 +235,7 @@ def main():
231
  )
232
 
233
  if __name__ == "__main__":
234
- main()
 
235
 
236
  # layout info https://github.com/zauberzeug/nicegui/discussions/1937
 
67
  # Global variables to track viewer and connection state
68
  viewer_initialized = False
69
  viewer_ready = False
70
+ ocpcv_proc = None
71
 
 
72
  def startup_all():
73
  global ocpcv_proc, viewer_initialized
74
  try:
75
+ if ocpcv_proc is not None:
76
+ logger.info("Viewer process already running")
77
+ return
78
+
79
  logger.info("Starting ocp_vscode subprocess")
80
  # spawn separate viewer process
81
  env = os.environ.copy() # Copy current environment
 
105
  """Check if the viewer is ready by attempting a test connection"""
106
  try:
107
  import requests
108
+ # Check the viewer directly since we're inside the container
109
+ response = requests.get('http://127.0.0.1:3939/viewer')
110
  return response.status_code == 200
111
  except Exception as e:
112
  logger.error(f"Error checking viewer: {str(e)}")
 
235
  )
236
 
237
  if __name__ == "__main__":
238
+ startup_all() # Start the viewer first
239
+ main() # Then start the UI
240
 
241
  # layout info https://github.com/zauberzeug/nicegui/discussions/1937