diff --git a/front/package.json b/front/package.json index 7a6e6dc..206adfd 100644 --- a/front/package.json +++ b/front/package.json @@ -3,7 +3,6 @@ "version": "0.1.0", "private": true, "homepage": ".", - "proxy": "http://10.82.17.56:8088/bookmark/api", "dependencies": { "antd": "^3.19.8", "axios": "^0.19.0", diff --git a/front/src/setupProxy.js b/front/src/setupProxy.js new file mode 100644 index 0000000..816b034 --- /dev/null +++ b/front/src/setupProxy.js @@ -0,0 +1,10 @@ +const proxy = require("http-proxy-middleware"); + +module.exports = function(app) { + app.use( + proxy("/bookmark/api/**", { + target: "http://10.82.17.56:8088/", + changeOrigin: true + }) + ); +}; diff --git a/front/src/util/httpUtil.js b/front/src/util/httpUtil.js index cc6ea7e..0fc4575 100644 --- a/front/src/util/httpUtil.js +++ b/front/src/util/httpUtil.js @@ -6,13 +6,22 @@ const history = createBrowserHistory(); //定义http实例 const instance = axios.create({ - // baseURL: "http://ali.tapme.top:8081/mock/16/chat/api/", - headers: { - "jwt-token": window.token - } + baseURL: "/bookmark/api", + timeout: 5000 }); -//实例添加拦截器 +//实例添加请求拦截器 +instance.interceptors.request.use( + req => { + req.headers["jwt-token"] = window.token; + return req; + }, + error => { + console.log(error); + } +); + +//实例添加响应拦截器 instance.interceptors.response.use( function(res) { console.log(res); @@ -27,7 +36,9 @@ instance.interceptors.response.use( } }, function(error) { + console.log(error); showError(error.response); + return Promise.reject(JSON.stringify(error)); } );