From 221b36496b787ec2b65ad6337cfe068c90981e07 Mon Sep 17 00:00:00 2001 From: Joan Code <172996447+joan-code6@users.noreply.github.com> Date: Thu, 27 Aug 2026 19:05:02 +0200 Subject: [PATCH] feat: configure UI host and port from config file --- .env.example | 7 ------- README.md | 18 +++++++++++++++++- config.json | 5 +++++ src/utils/backendConfig.ts | 6 +++--- src/vite-env.d.ts | 9 --------- tsconfig.node.json | 5 +++-- vite.config.ts | 13 +++++++++---- 7 files changed, 37 insertions(+), 26 deletions(-) delete mode 100644 .env.example create mode 100644 config.json diff --git a/.env.example b/.env.example deleted file mode 100644 index e0700f20..00000000 --- a/.env.example +++ /dev/null @@ -1,7 +0,0 @@ -# Environment Configuration - -# API Configuration -VITE_API_URL=http://localhost:8000 - -# Optional: Enable development features -NODE_ENV=development \ No newline at end of file diff --git a/README.md b/README.md index 9bc76236..ae67572d 100644 --- a/README.md +++ b/README.md @@ -1 +1,17 @@ -# Lanis WEB UI \ No newline at end of file +# Lanis WEB UI + +## Configuration + +Edit [`config.json`](config.json) before starting the UI: + +```json +{ + "host": "0.0.0.0", + "port": 3000, + "apiUrl": "http://localhost:8000" +} +``` + +`host` and `port` configure the Vite development and preview servers. `apiUrl` +sets the default LANIS API address used by the browser. No environment variables +are required for these settings. diff --git a/config.json b/config.json new file mode 100644 index 00000000..0444b5c1 --- /dev/null +++ b/config.json @@ -0,0 +1,5 @@ +{ + "host": "0.0.0.0", + "port": 3000, + "apiUrl": "http://localhost:8000" +} diff --git a/src/utils/backendConfig.ts b/src/utils/backendConfig.ts index b1502851..73a0d50d 100644 --- a/src/utils/backendConfig.ts +++ b/src/utils/backendConfig.ts @@ -1,8 +1,8 @@ +import uiConfig from '../../config.json'; + export const CUSTOM_BACKEND_STORAGE_KEY = 'lanis_custom_backend_url'; -export const DEFAULT_API_BASE_URL = ( - import.meta.env.VITE_API_URL || 'http://localhost:8000' -).replace(/\/+$/, ''); +export const DEFAULT_API_BASE_URL = uiConfig.apiUrl.replace(/\/+$/, ''); const BACKEND_SCOPED_STORAGE_KEYS = [ 'auth_access_token', diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 79b2836f..11f02fe2 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -1,10 +1 @@ /// - -interface ImportMetaEnv { - readonly VITE_API_URL: string - // more env variables... -} - -interface ImportMeta { - readonly env: ImportMetaEnv -} \ No newline at end of file diff --git a/tsconfig.node.json b/tsconfig.node.json index 099658cf..9955f3e6 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -4,7 +4,8 @@ "skipLibCheck": true, "module": "ESNext", "moduleResolution": "bundler", - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "resolveJsonModule": true }, "include": ["vite.config.ts"] -} \ No newline at end of file +} diff --git a/vite.config.ts b/vite.config.ts index 1a3173f0..48c86c41 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,17 +1,22 @@ +import uiConfig from './config.json' import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' export default defineConfig({ plugins: [react()], server: { - port: 3000, - host: true, + port: uiConfig.port, + host: uiConfig.host, proxy: { '/api': { - target: 'http://localhost:8000', + target: uiConfig.apiUrl, changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, ''), }, }, }, -}) \ No newline at end of file + preview: { + port: uiConfig.port, + host: uiConfig.host, + }, +})