Mercurial > code > home > repos > light9
changeset 2051:bfee787d7b5c
straighten out proxying and nginx+vite mixing
author | drewp@bigasterisk.com |
---|---|
date | Fri, 13 May 2022 01:07:15 -0700 |
parents | 7ed414bdaab9 |
children | cba85338def9 |
files | bin/collector bin/homepageConfig light9/ascoltami/vite.config.ts light9/collector/web/index.html light9/collector/web/vite.config.ts light9/homepage/vite.config.ts |
diffstat | 6 files changed, 58 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/bin/collector Wed May 11 00:07:13 2022 -0700 +++ b/bin/collector Fri May 13 01:07:15 2022 -0700 @@ -1,5 +1,5 @@ #!/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
--- 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')
--- a/light9/ascoltami/vite.config.ts Wed May 11 00:07:13 2022 -0700 +++ b/light9/ascoltami/vite.config.ts Fri May 13 01:07:15 2022 -0700 @@ -1,18 +1,20 @@ 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: {}, }, }); -
--- a/light9/collector/web/index.html Wed May 11 00:07:13 2022 -0700 +++ b/light9/collector/web/index.html Fri May 13 01:07:15 2022 -0700 @@ -63,7 +63,7 @@ <td>{{item.chan}}</td> </tr> </template> - + </table> </template> <script> HTMLImports.whenReady(function () {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/light9/collector/web/vite.config.ts Fri May 13 01:07:15 2022 -0700 @@ -0,0 +1,20 @@ +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: {}, + }, +});
--- a/light9/homepage/vite.config.ts Wed May 11 00:07:13 2022 -0700 +++ b/light9/homepage/vite.config.ts Fri May 13 01:07:15 2022 -0700 @@ -1,16 +1,19 @@ 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: {}, },