pass hub version through html and update dependencies

- Changed Vite configuration to replace version during development.
This commit is contained in:
henrygd
2025-03-13 02:15:03 -04:00
parent 1d7c0ebc27
commit ae22334645
8 changed files with 195 additions and 323 deletions

View File

@@ -172,6 +172,7 @@ func (h *Hub) startServer(se *core.ServeEvent) error {
basePath := strings.TrimSuffix(parsedURL.Path, "/") + "/"
indexFile, _ := fs.ReadFile(site.DistDirFS, "index.html")
indexContent := strings.ReplaceAll(string(indexFile), "./", basePath)
indexContent = strings.Replace(indexContent, "{{V}}", beszel.Version, 1)
// set up static asset serving
staticPaths := [2]string{"/static/", "/assets/"}
serveStatic := apis.Static(site.DistDirFS, false)

Binary file not shown.

View File

@@ -6,7 +6,12 @@
<link rel="icon" type="image/svg+xml" href="./static/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Beszel</title>
<script>window.BASE_PATH = "%BASE_URL%"</script>
<script>
globalThis.BESZEL = {
BASE_PATH: "%BASE_URL%",
HUB_VERSION: "{{V}}"
}
</script>
</head>
<body>
<div id="app"></div>

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
{
"name": "beszel",
"private": true,
"version": "0.0.0",
"version": "0.10.1",
"type": "module",
"scripts": {
"dev": "vite",
@@ -12,9 +12,10 @@
},
"dependencies": {
"@henrygd/queue": "^1.0.7",
"@lingui/detect-locale": "^4.14.1",
"@lingui/macro": "^4.14.1",
"@lingui/react": "^4.14.1",
"@henrygd/semaphore": "^0.0.2",
"@lingui/detect-locale": "^5.2.0",
"@lingui/macro": "^5.2.0",
"@lingui/react": "^5.2.0",
"@nanostores/react": "^0.7.3",
"@nanostores/router": "^0.11.0",
"@radix-ui/react-alert-dialog": "^1.1.6",
@@ -48,7 +49,7 @@
},
"devDependencies": {
"@lingui/cli": "^5.2.0",
"@lingui/swc-plugin": "^5.4.0",
"@lingui/swc-plugin": "^5.5.0",
"@lingui/vite-plugin": "^5.2.0",
"@types/bun": "^1.2.4",
"@types/react": "^18.3.1",

View File

@@ -11,7 +11,7 @@ const routes = {
* The base path of the application.
* This is used to prepend the base path to all routes.
*/
export const basePath = window.BASE_PATH || ""
export const basePath = globalThis.BESZEL.BASE_PATH || ""
/**
* Prepends the base path to the given path.

View File

@@ -2,8 +2,9 @@ import { RecordModel } from "pocketbase"
// global window properties
declare global {
interface Window {
var BESZEL: {
BASE_PATH: string
HUB_VERSION: string
}
}

View File

@@ -2,6 +2,7 @@ import { defineConfig } from "vite"
import path from "path"
import react from "@vitejs/plugin-react-swc"
import { lingui } from "@lingui/vite-plugin"
import { version } from "./package.json"
export default defineConfig({
base: "./",
@@ -10,6 +11,13 @@ export default defineConfig({
plugins: [["@lingui/swc-plugin", {}]],
}),
lingui(),
{
name: "replace version in index.html during dev",
apply: "serve",
transformIndexHtml(html) {
return html.replace("{{V}}", version)
},
},
],
esbuild: {
legalComments: "external",