Move proxy url to env file

This commit is contained in:
cuigh 2021-12-22 18:05:53 +08:00
parent 487d73d643
commit 63cc555e21
3 changed files with 6 additions and 3 deletions

1
ui/.env.development Normal file
View File

@ -0,0 +1 @@
VITE_PROXY_URL='localhost:8001'

View File

@ -51,7 +51,7 @@ function connect() {
active.value = true active.value = true
let protocol = (location.protocol === "https:") ? "wss://" : "ws://"; let protocol = (location.protocol === "https:") ? "wss://" : "ws://";
let host = import.meta.env.DEV ? 'localhost:8001' : location.host; let host = import.meta.env.DEV ? import.meta.env.VITE_PROXY_URL : location.host;
let cmd = encodeURIComponent(command.value) let cmd = encodeURIComponent(command.value)
socket = new WebSocket(`${protocol}${host}/api/container/connect?token=${store.state.user.token}&node=${props.node}&id=${props.id}&cmd=${cmd}`); socket = new WebSocket(`${protocol}${host}/api/container/connect?token=${store.state.user.token}&node=${props.node}&id=${props.id}&cmd=${cmd}`);
socket.onopen = () => { socket.onopen = () => {

View File

@ -1,7 +1,9 @@
import { defineConfig } from 'vite' import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import path from 'path' import path from 'path'
const config = loadEnv('development', './')
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [vue()], plugins: [vue()],
@ -28,7 +30,7 @@ export default defineConfig({
port: 3002, port: 3002,
proxy: { proxy: {
'/api': { '/api': {
target: 'http://localhost:8001', target: 'http://' + config.VITE_PROXY_URL,
changeOrigin: true, changeOrigin: true,
}, },
} }