diff bin/homepageConfig @ 2051:bfee787d7b5c

straighten out proxying and nginx+vite mixing
author drewp@bigasterisk.com
date Fri, 13 May 2022 01:07:15 -0700
parents 04ed5d134973
children a415be4cfac4
line wrap: on
line diff
--- a/bin/homepageConfig	Wed May 11 00:07:13 2022 -0700
+++ b/bin/homepageConfig	Fri May 13 01:07:15 2022 -0700
@@ -15,20 +15,33 @@
 print("listen %s;" % splitport(urlparse(webServer).netloc)[1])
 
 
-def location(path, server):
+def location(path, server, viteServer):
     print(f"""
-    location /{path}/ {{
+
+    location = /{path}/metrics {{
+      rewrite ^/{path}(/.*) $1 break;
+      proxy_pass {server}; 
+    }}
 
-      # for websocket
-      proxy_http_version 1.1;
-      proxy_set_header Upgrade $http_upgrade;
-      proxy_set_header Connection "upgrade";
-      proxy_set_header Host $host;
+    location /{path}/api/ {{
+      # just the tail part for services
+      rewrite ^/{path}/api(/.*) $1 break;
+      proxy_pass {server}; 
+    }}
+    location /{path}/ {{
+      # vite has 'base' to deal with the /{path}/ part of the request
+      proxy_pass {viteServer}; 
+    }}
 
-      proxy_pass {server};
-      proxy_buffering off;
-      rewrite /[^/]+/(.*) /$1 break;
-    }}""")
+# vite seems to work without this old section-- hopefully other services will too!
+    #   # for websocket
+    #   proxy_http_version 1.1;
+    #   proxy_set_header Upgrade $http_upgrade;
+    #   proxy_set_header Connection "upgrade";
+    #   proxy_set_header Host $host;
+
+    #   proxy_buffering off;
+    """)
 
 
 for role, server in sorted(graph.predicate_objects(netHome)):
@@ -38,20 +51,8 @@
     if not path:
         continue
     server = server.rstrip('/')
-    if 'collector' in path: continue
-    location(path, server)
-
-print('''
-
-  location /collector/metrics {
-    rewrite "/collector(/.*)" "$1" break;
-    proxy_pass http://localhost:8202;
-  }
-  location /collector/ {
-    proxy_pass http://localhost:8302;
-  }
-
-''')
+    viteServer = server.replace('820', '830') # rewrite this please
+    location(path, server, viteServer)
 
 showPath = showconfig.showUri().split('/', 3)[-1]
 root = showconfig.root()[:-len(showPath)].decode('ascii')