From 63cc555e21c1fc39846d5d430d5db61aa0ee8d0d Mon Sep 17 00:00:00 2001 From: cuigh Date: Wed, 22 Dec 2021 18:05:53 +0800 Subject: [PATCH] Move proxy url to env file --- ui/.env.development | 1 + ui/src/pages/container/modules/Execute.vue | 2 +- ui/vite.config.ts | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 ui/.env.development diff --git a/ui/.env.development b/ui/.env.development new file mode 100644 index 0000000..73870c5 --- /dev/null +++ b/ui/.env.development @@ -0,0 +1 @@ +VITE_PROXY_URL='localhost:8001' diff --git a/ui/src/pages/container/modules/Execute.vue b/ui/src/pages/container/modules/Execute.vue index 2298268..e8a9eaa 100644 --- a/ui/src/pages/container/modules/Execute.vue +++ b/ui/src/pages/container/modules/Execute.vue @@ -51,7 +51,7 @@ function connect() { active.value = true 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) socket = new WebSocket(`${protocol}${host}/api/container/connect?token=${store.state.user.token}&node=${props.node}&id=${props.id}&cmd=${cmd}`); socket.onopen = () => { diff --git a/ui/vite.config.ts b/ui/vite.config.ts index b0bf8c0..5746726 100644 --- a/ui/vite.config.ts +++ b/ui/vite.config.ts @@ -1,7 +1,9 @@ -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' import path from 'path' +const config = loadEnv('development', './') + // https://vitejs.dev/config/ export default defineConfig({ plugins: [vue()], @@ -28,7 +30,7 @@ export default defineConfig({ port: 3002, proxy: { '/api': { - target: 'http://localhost:8001', + target: 'http://' + config.VITE_PROXY_URL, changeOrigin: true, }, }