Commit 7ec833b7 authored by 邓超's avatar 邓超

fix: 修改网关拼接问题

parent c35ae5d7
Pipeline #66495 passed with stages
...@@ -7,8 +7,8 @@ import toLower from 'lodash/toLower'; ...@@ -7,8 +7,8 @@ import toLower from 'lodash/toLower';
import isFunction from 'lodash/isFunction'; import isFunction from 'lodash/isFunction';
import extendConfig from './defaultConfig'; import extendConfig from './defaultConfig';
const globalConfig = { const globalConfig = {
bizRedirectHandler: extendConfig.bizRedirectHandler bizRedirectHandler: extendConfig.bizRedirectHandler,
} };
const globalConfigMatchers = []; const globalConfigMatchers = [];
/* no-unused-vars */ /* no-unused-vars */
const getMatchedConfig = requestConfig => { const getMatchedConfig = requestConfig => {
...@@ -19,42 +19,54 @@ const getMatchedConfig = requestConfig => { ...@@ -19,42 +19,54 @@ const getMatchedConfig = requestConfig => {
const [matcher, extendConfig] = globalConfigMatchers[i]; const [matcher, extendConfig] = globalConfigMatchers[i];
// 匹配到第一个matcher就返回了, 存在后续配置不生效的情况 // 匹配到第一个matcher就返回了, 存在后续配置不生效的情况
if (matcher(requestConfig)) { if (matcher(requestConfig)) {
console.log(`matched url: ${requestConfig.url}`) console.log(`matched url: ${requestConfig.url}`);
return extendConfig; return extendConfig;
} }
return null; return null;
} }
}; };
axios.defaults.withCredentials = true axios.defaults.withCredentials = true;
axios.interceptors.request.use( function (request){ axios.interceptors.request.use(
const token = localStorage.getItem('token') function(request) {
const pandaPublish = localStorage.getItem('panda-publish') const token = localStorage.getItem('token');
const getWay = '/PandaCore/GateWay' const pandaPublish = localStorage.getItem('panda-publish');
if(token){ const getWay = '/PandaCore/GateWay';
request.headers.Authorization = 'Bearer ' + token if (token) {
} request.headers.Authorization = 'Bearer ' + token;
if(pandaPublish){
if(request.url!='/PandaOMS/OMS/OMSLogin'&&request.url!='/Publish/OMS/FileCenter/SaveMobileApk'&&request.url!='/PandaOMS/OMS/HostManager/GetGateWay')
request.url=getWay+request.url
}
return request
}, function (error) {
// Any status codes that falls outside the range of 2xx cause this function to trigger
// Do something with response error
return Promise.reject(error);
})
axios.interceptors.response.use(function (response) {
return response
}, (error) => {
if (error.response) {
switch (error.response.status) {
case 401:
globalConfig.bizRedirectHandler(error.response)
} }
} if (pandaPublish) {
return Promise.reject(error); console.log(request.url, 'request.url');
}) if (
request.url != '/PandaOMS/OMS/OMSLogin' &&
request.url != '/Publish/OMS/FileCenter/SaveMobileApk' &&
request.url != '/PandaOMS/OMS/HostManager/GetGateWay' &&
request.url != '/PandaCore/GateWay/OcelotSettings/GetReRoutes'
)
request.url = getWay + request.url;
}
return request;
},
function(error) {
// Any status codes that falls outside the range of 2xx cause this function to trigger
// Do something with response error
return Promise.reject(error);
},
);
axios.interceptors.response.use(
function(response) {
return response;
},
error => {
if (error.response) {
switch (error.response.status) {
case 401:
globalConfig.bizRedirectHandler(error.response);
}
}
return Promise.reject(error);
},
);
export const request = (config, ctx) => { export const request = (config, ctx) => {
const { const {
...@@ -106,7 +118,8 @@ export const request = (config, ctx) => { ...@@ -106,7 +118,8 @@ export const request = (config, ctx) => {
requestOptions = bizRequestAdapter(requestOptions); requestOptions = bizRequestAdapter(requestOptions);
} }
return axios(requestOptions).then(raw => raw && raw.data) return axios(requestOptions)
.then(raw => raw && raw.data)
.then( .then(
res => res =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
...@@ -119,9 +132,7 @@ export const request = (config, ctx) => { ...@@ -119,9 +132,7 @@ export const request = (config, ctx) => {
const errorDesc = bizDevErrorAdapter ? bizDevErrorAdapter(res) : null; const errorDesc = bizDevErrorAdapter ? bizDevErrorAdapter(res) : null;
// 3. 用户级错误信息转换 // 3. 用户级错误信息转换
const errorMsg = bizErrorMessageAdapter const errorMsg = bizErrorMessageAdapter ? bizErrorMessageAdapter(res) : null;
? bizErrorMessageAdapter(res)
: null;
// 4. 成功信息转换 // 4. 成功信息转换
const successMsg = bizSuccessMessageAdapter const successMsg = bizSuccessMessageAdapter
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment