Made proxy target configurable

This commit is contained in:
Gunnar Skjold
2026-03-05 16:39:20 +01:00
parent 640e957065
commit 6743750d8f
2 changed files with 40 additions and 23 deletions

View File

@@ -1,6 +1,16 @@
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
// Try to import local config, fall back to default if not found
let localConfig = { proxyTarget: "http://192.168.4.1" };
try {
const imported = await import('./vite.config.local.js');
localConfig = imported.default;
} catch (e) {
console.log('No vite.config.local.js found, using default proxy target:', localConfig.proxyTarget);
console.log('Copy vite.config.local.example.js to vite.config.local.js to customize');
}
// https://vitejs.dev/config/
export default defineConfig({
build: {
@@ -24,29 +34,29 @@ export default defineConfig({
})],
server: {
proxy: {
"/data.json": "http://192.168.21.122",
"/energyprice.json": "http://192.168.21.122",
"/importprice.json": "http://192.168.21.122",
"/exportprice.json": "http://192.168.21.122",
"/dayplot.json": "http://192.168.21.122",
"/monthplot.json": "http://192.168.21.122",
"/temperature.json": "http://192.168.21.122",
"/sysinfo.json": "http://192.168.21.122",
"/configuration.json": "http://192.168.21.122",
"/tariff.json": "http://192.168.21.122",
"/realtime.json": "http://192.168.21.122",
"/priceconfig.json": "http://192.168.21.122",
"/translations.json": "http://192.168.21.122",
"/cloudkey.json": "http://192.168.21.122",
"/wifiscan.json": "http://192.168.21.122",
"/save": "http://192.168.21.122",
"/reboot": "http://192.168.21.122",
"/configfile": "http://192.168.21.122",
"/upgrade": "http://192.168.21.122",
"/mqtt-ca": "http://192.168.21.122",
"/mqtt-cert": "http://192.168.21.122",
"/mqtt-key": "http://192.168.21.122",
"/logo.svg": "http://192.168.21.122",
"/data.json": localConfig.proxyTarget,
"/energyprice.json": localConfig.proxyTarget,
"/importprice.json": localConfig.proxyTarget,
"/exportprice.json": localConfig.proxyTarget,
"/dayplot.json": localConfig.proxyTarget,
"/monthplot.json": localConfig.proxyTarget,
"/temperature.json": localConfig.proxyTarget,
"/sysinfo.json": localConfig.proxyTarget,
"/configuration.json": localConfig.proxyTarget,
"/tariff.json": localConfig.proxyTarget,
"/realtime.json": localConfig.proxyTarget,
"/priceconfig.json": localConfig.proxyTarget,
"/translations.json": localConfig.proxyTarget,
"/cloudkey.json": localConfig.proxyTarget,
"/wifiscan.json": localConfig.proxyTarget,
"/save": localConfig.proxyTarget,
"/reboot": localConfig.proxyTarget,
"/configfile": localConfig.proxyTarget,
"/upgrade": localConfig.proxyTarget,
"/mqtt-ca": localConfig.proxyTarget,
"/mqtt-cert": localConfig.proxyTarget,
"/mqtt-key": localConfig.proxyTarget,
"/logo.svg": localConfig.proxyTarget,
}
}
})

View File

@@ -0,0 +1,7 @@
// Copy this file to vite.config.local.js and update with your device's IP address
// vite.config.local.js is ignored by git so your settings won't be committed
export default {
// The IP address of your AMS reader device for local development
proxyTarget: "http://192.168.4.1"
}