refactor(Logs): use APP_TARGET to read target websocket addr
refactor(config): use APP_TARGET constant for backend URL configuration Centralize backend URL configuration by introducing APP_TARGET constant in vite.config.js and using it for both WebSocket connection and API proxy. This improves maintainability by having a single source of truth for the backend address.
This commit is contained in:
@@ -61,7 +61,8 @@ export default {
|
|||||||
const connectWebSocket = () => {
|
const connectWebSocket = () => {
|
||||||
const token = getCookie('token');
|
const token = getCookie('token');
|
||||||
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
const wsUrl = `${wsProtocol}//localhost:8080/system/getLogs?token=${token}`;
|
const target = __APP_TARGET__;
|
||||||
|
const wsUrl = `${wsProtocol}//${target}/system/getLogs?token=${token}`;
|
||||||
|
|
||||||
socket.value = new WebSocket(wsUrl);
|
socket.value = new WebSocket(wsUrl);
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
|
|
||||||
|
const APP_TARGET = '192.168.1.4:38080'
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
define: {
|
||||||
|
__APP_TARGET__: JSON.stringify(APP_TARGET)
|
||||||
|
},
|
||||||
plugins: [vue()],
|
plugins: [vue()],
|
||||||
server: {
|
server: {
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
port: 3000,
|
port: 3000,
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: 'http://192.168.1.4:38080',
|
target: `http://${APP_TARGET}`,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path) => path.replace(/^\/api/, '')
|
rewrite: (path) => path.replace(/^\/api/, '')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user