mirror of https://github.com/jetkvm/kvm.git
feat: add router functionality and build script for versioned assets
- Introduced a new router in `functions/router/index.js` to handle requests for HTML and asset files based on versioning. - Created `functions/router/package.json` for the router module. - Added a build script `ui/build-all.sh` to automate the building of assets for multiple firmware versions. - Updated `ui/package.json` to include a new build script command for building all versions.
This commit is contained in:
parent
d24ce1c76f
commit
7b92ba6354
|
|
@ -0,0 +1,28 @@
|
|||
export default async function(req) {
|
||||
const url = new URL(req.url);
|
||||
const path = url.pathname;
|
||||
|
||||
// Determine version from path
|
||||
let version = 'latest';
|
||||
if (path.startsWith('/v/')) {
|
||||
const match = path.match(/^\/v\/([^\/]+)/);
|
||||
if (match) version = match[1];
|
||||
}
|
||||
|
||||
// For HTML navigation (no file extension), serve index.html
|
||||
if (!path.match(/\.[a-z]+$/i)) {
|
||||
const htmlUrl = `https://${url.host}/v/${version}/index.html`;
|
||||
const response = await fetch(htmlUrl);
|
||||
return new Response(response.body, {
|
||||
headers: {
|
||||
'Content-Type': 'text/html',
|
||||
'Cache-Control': 'no-cache'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// For assets, pass through
|
||||
const assetUrl = `https://${url.host}${path}`;
|
||||
return fetch(assetUrl);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "router",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js"
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Build latest (includes device list)
|
||||
echo "Building latest..."
|
||||
VITE_BASE_PATH=/v/latest/ npm run build:prod -- --outDir dist-temp
|
||||
mkdir -p dist/v/latest
|
||||
cp -r dist-temp/* dist/v/latest/
|
||||
|
||||
# Build for each firmware version you support
|
||||
echo "Building v2025.11.07..."
|
||||
VITE_BASE_PATH=/v/2025.11.07/ npm run build:prod -- --outDir dist-temp
|
||||
mkdir -p dist/v/2025.11.07
|
||||
cp -r dist-temp/* dist/v/2025.11.07/
|
||||
|
||||
echo "Building v2025.10.15..."
|
||||
VITE_BASE_PATH=/v/2025.10.15/ npm run build:prod -- --outDir dist-temp
|
||||
mkdir -p dist/v/2025.10.15
|
||||
cp -r dist-temp/* dist/v/2025.10.15/
|
||||
|
||||
rm -rf dist-temp
|
||||
echo "✓ All versions built to dist/v/"
|
||||
|
||||
|
|
@ -4,13 +4,14 @@
|
|||
"version": "2025.11.07.2130",
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": "^22.20.0"
|
||||
"node": "22.x"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "./dev_device.sh",
|
||||
"dev:ssl": "USE_SSL=true ./dev_device.sh",
|
||||
"dev:cloud": "vite dev --mode=cloud-development",
|
||||
"build": "npm run build:prod",
|
||||
"build:all": "./build-all.sh",
|
||||
"build:device": "npm run i18n:compile && tsc && vite build --mode=device --emptyOutDir",
|
||||
"build:staging": "npm run i18n:compile && tsc && vite build --mode=cloud-staging",
|
||||
"build:prod": "npm run i18n:compile && tsc && vite build --mode=cloud-production",
|
||||
|
|
|
|||
Loading…
Reference in New Issue