diff --git a/src/config/api.js b/src/config/api.js index cc6991b2..3f1cd975 100644 --- a/src/config/api.js +++ b/src/config/api.js @@ -1,11 +1,11 @@ // API配置文件 const API_CONFIG = { // 后端服务基础URL - BASE_URL: 'http://localhost:8086', + BASE_URL: '', // API端点 ENDPOINTS: { - DEVICES: '/api/v1/devices' + DEVICES: '/v1/devices' }, // 请求超时时间(毫秒) diff --git a/src/utils/http.js b/src/utils/http.js index 8c00a895..4864bbf5 100644 --- a/src/utils/http.js +++ b/src/utils/http.js @@ -1,7 +1,8 @@ import axios from 'axios'; import API_CONFIG from '../config/api.js'; -// 创建axios实例 +// 创建axios实例,自动将请求发送到 BASE_URL + 相对路径 +// 例如:http.get('/api/pigs') 会请求 BASE_URL + '/api/pigs' const http = axios.create({ baseURL: API_CONFIG.BASE_URL, timeout: API_CONFIG.TIMEOUT, diff --git a/webpack.config.js b/webpack.config.js index 6a413177..895f5ed9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -46,7 +46,14 @@ module.exports = (env, argv) => { hot: true, open: true, historyApiFallback: true, - port: 8080 + port: 8080, + proxy: { + '/api': { + target: 'http://localhost:8086', + changeOrigin: true, + secure: false + } + } }, resolve: { alias: {