Changeset - bfee787d7b5c
[Not reviewed]
default
0 5 1
drewp@bigasterisk.com - 3 years ago 2022-05-13 08:07:15
drewp@bigasterisk.com
straighten out proxying and nginx+vite mixing
6 files changed with 58 insertions and 32 deletions:
0 comments (0 inline, 0 general)
bin/collector
Show inline comments
 
#!/bin/sh
 
pnpx vite -c light9/collector/web/vite.config.ts &
 
pdm run uvicorn light9.collector.service:app --host 0.0.0.0 --port 8202
 
pdm run uvicorn light9.collector.service:app --host 0.0.0.0 --port 8202 --no-access-log
 
wait
 

	
bin/homepageConfig
Show inline comments
 
@@ -12,49 +12,50 @@ netHome = graph.value(showconfig.showUri
 
webServer = graph.value(netHome, L9['webServer'])
 
if not webServer:
 
    raise ValueError('no %r :webServer' % netHome)
 
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)):
 
    if not server.startswith('http') or role == L9['webServer']:
 
        continue
 
    path = graph.value(role, L9['urlPath'])
 
    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')
 
print(f"""
 
    location /{showPath} {{
 
      root {root};
light9/ascoltami/vite.config.ts
Show inline comments
 
import { defineConfig } from "vite";
 

	
 
const servicePort = 8206;
 
export default defineConfig({
 
  base: "/ascoltami/",
 
  root: "./light9/ascoltami",
 
  publicDir: "../web",
 
  server: {
 
    host: "0.0.0.0",
 
    strictPort: true,
 
    port: 8306,
 
    port: servicePort + 100,
 
    hmr: {
 
      port: 8406,
 
      port: servicePort + 200,
 
    },
 
  },
 
  clearScreen: false,
 
  define: {
 
    global: {},
 
  },
 
});
 

	
light9/collector/web/index.html
Show inline comments
 
@@ -60,13 +60,13 @@
 
            <tr>
 
              <td>{{item.attr}}</td>
 
              <td class$="{{item.valClass}}">{{item.val}} →</td>
 
              <td>{{item.chan}}</td>
 
            </tr>
 
          </template>
 

	
 
        </table>
 
      </template>
 
      <script>
 
       HTMLImports.whenReady(function () {
 
         Polymer({
 
           is: "light9-collector-device",
 
           properties: {
light9/collector/web/vite.config.ts
Show inline comments
 
new file 100644
 
import { defineConfig } from "vite";
 

	
 
const servicePort = 8202;
 
export default defineConfig({
 
  base: "/collector/",
 
  root: "./light9/collector/web",
 
  publicDir: "../web",
 
  server: {
 
    host: "0.0.0.0",
 
    strictPort: true,
 
    port: servicePort + 100,
 
    hmr: {
 
      port: servicePort + 200,
 
    },
 
  },
 
  clearScreen: false,
 
  define: {
 
    global: {},
 
  },
 
});
light9/homepage/vite.config.ts
Show inline comments
 
import { defineConfig } from "vite";
 

	
 
const servicePort = 8200; // (not really, for homepage)
 
export default defineConfig({
 
  base: "/",
 
  root: "./light9/homepage",
 
  publicDir: "../web",
 
  server: {
 
    host: "0.0.0.0",
 
    strictPort: true,
 
    port: 8300,
 
    port: servicePort + 100,
 
    hmr: {
 
      port: 8400,
 
      port: servicePort + 200,
 
    },
 
  },
 
  clearScreen: false,
 
  define: {
 
    global: {},
 
  },
 
});
0 comments (0 inline, 0 general)