fix: 还原配置

main
ChenZhaoYu 2 years ago
parent c0f8e4316e
commit b84f7e4c72

@ -1,5 +1,7 @@
# Glob API URL # Glob API URL
VITE_GLOB_API_URL=http://localhost:3002 VITE_GLOB_API_URL=/api
VITE_APP_API_BASE_URL=http://localhost:3002/
# Glob API Timeout (ms) # Glob API Timeout (ms)
VITE_GLOB_API_TIMEOUT=100000 VITE_GLOB_API_TIMEOUT=100000

@ -3,5 +3,5 @@
interface ImportMetaEnv { interface ImportMetaEnv {
readonly VITE_GLOB_API_URL: string; readonly VITE_GLOB_API_URL: string;
readonly VITE_GLOB_API_TIMEOUT: string; readonly VITE_GLOB_API_TIMEOUT: string;
readonly VITE_GLOB_HTTP_PROXY: 'Y' | 'N'; readonly VITE_APP_API_BASE_URL: string;
} }

@ -1,7 +1,7 @@
import axios, { type AxiosResponse } from 'axios' import axios, { type AxiosResponse } from 'axios'
const service = axios.create({ const service = axios.create({
baseURL: import.meta.env.VITE_GLOB_HTTP_PROXY === 'Y' ? '/api' : import.meta.env.VITE_GLOB_API_URL, baseURL: import.meta.env.VITE_GLOB_API_URL,
timeout: !isNaN(+import.meta.env.VITE_GLOB_API_TIMEOUT) ? Number(import.meta.env.VITE_GLOB_API_TIMEOUT) : 60 * 1000, timeout: !isNaN(+import.meta.env.VITE_GLOB_API_TIMEOUT) ? Number(import.meta.env.VITE_GLOB_API_TIMEOUT) : 60 * 1000,
}) })

@ -1,13 +1,10 @@
import path from 'path' import path from 'path'
import { defineConfig, loadEnv } from 'vite' import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import { createViteProxy } from './config'
export default defineConfig((env) => { export default defineConfig((env) => {
const viteEnv = loadEnv(env.mode, process.cwd()) as unknown as ImportMetaEnv const viteEnv = loadEnv(env.mode, process.cwd()) as unknown as ImportMetaEnv
const isOpenProxy = viteEnv.VITE_GLOB_HTTP_PROXY === 'Y'
return { return {
resolve: { resolve: {
alias: { alias: {
@ -19,7 +16,13 @@ export default defineConfig((env) => {
host: '0.0.0.0', host: '0.0.0.0',
port: 1002, port: 1002,
open: false, open: false,
proxy: createViteProxy(isOpenProxy, viteEnv), proxy: {
'/api': {
target: viteEnv.VITE_APP_API_BASE_URL,
changeOrigin: true, // 允许跨域
rewrite: path => path.replace('/api/', '/'),
},
},
}, },
build: { build: {
reportCompressedSize: false, reportCompressedSize: false,

Loading…
Cancel
Save