Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .env.example

This file was deleted.

18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# Lanis WEB UI
# 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.
5 changes: 5 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"host": "0.0.0.0",
"port": 3000,
"apiUrl": "http://localhost:8000"
}
6 changes: 3 additions & 3 deletions src/utils/backendConfig.ts
Original file line number Diff line number Diff line change
@@ -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(/\/+$/, '');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Load apiUrl at runtime rather than bundling it

When a prebuilt dist is started with vite preview, changing config.json as README.md instructs updates the preview host and port but not the browser's API address: importing the JSON here causes Vite to inline apiUrl during vite build. This is especially problematic for a single artifact deployed to multiple environments, because every client continues using the build-time URL—by default its own localhost:8000—until the application is rebuilt. Either expose the configuration as a runtime-loaded public file or document and enforce that apiUrl must be set before building.

Useful? React with 👍 / 👎.


const BACKEND_SCOPED_STORAGE_KEYS = [
'auth_access_token',
Expand Down
9 changes: 0 additions & 9 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_API_URL: string
// more env variables...
}

interface ImportMeta {
readonly env: ImportMetaEnv
}
5 changes: 3 additions & 2 deletions tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true
},
"include": ["vite.config.ts"]
}
}
13 changes: 9 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -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/, ''),
},
},
},
})
preview: {
port: uiConfig.port,
host: uiConfig.host,
},
})