diff --git a/src/utils/auth.js b/src/utils/auth.js index 92df9c1..9396915 100644 --- a/src/utils/auth.js +++ b/src/utils/auth.js @@ -26,7 +26,7 @@ export async function autoLogin() { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: 'admin', - password: 'FAD888888' + password: 'admin123' }) }) diff --git a/src/utils/request.js b/src/utils/request.js index dd99328..44446af 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -1,10 +1,6 @@ import axios from 'axios' -// 走 Nginx 代理,同域名请求 -const baseURL = '/api' - const service = axios.create({ - baseURL: baseURL, timeout: 30000 }) @@ -25,6 +21,12 @@ const getToken = () => { service.interceptors.request.use( config => { + // 统一加 /api 前缀(生产环境 Nginx 代理用,开发环境 Vite 代理用) + // 如果 URL 已带 /api/ 或已是绝对地址,则跳过 + if (!config.url.startsWith('/api/') && !config.url.startsWith('http')) { + config.url = '/api' + config.url + } + const token = getToken() if (token) { diff --git a/vite.config.js b/vite.config.js index 7b114c3..42f587c 100644 --- a/vite.config.js +++ b/vite.config.js @@ -13,31 +13,8 @@ export default defineConfig({ proxy: { '/api': { target: 'http://localhost:8080', - changeOrigin: true - }, - '/da': { - target: 'http://localhost:8080', - changeOrigin: true - }, - '/pocket': { - target: 'http://localhost:8080', - changeOrigin: true - }, - '/l2': { - target: 'http://localhost:8080', - changeOrigin: true - }, - '/wms': { - target: 'http://localhost:8080', - changeOrigin: true - }, - '/oee': { - target: 'http://localhost:8080', - changeOrigin: true - }, - '/crm': { - target: 'http://localhost:8080', - changeOrigin: true + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api/, '') } } }