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

fix: 修改网关拼接问题

parent c35ae5d7
Pipeline #66495 passed with stages
......@@ -7,8 +7,8 @@ import toLower from 'lodash/toLower';
import isFunction from 'lodash/isFunction';
import extendConfig from './defaultConfig';
const globalConfig = {
bizRedirectHandler: extendConfig.bizRedirectHandler
}
bizRedirectHandler: extendConfig.bizRedirectHandler,
};
const globalConfigMatchers = [];
/* no-unused-vars */
const getMatchedConfig = requestConfig => {
......@@ -19,42 +19,54 @@ const getMatchedConfig = requestConfig => {
const [matcher, extendConfig] = globalConfigMatchers[i];
// 匹配到第一个matcher就返回了, 存在后续配置不生效的情况
if (matcher(requestConfig)) {
console.log(`matched url: ${requestConfig.url}`)
console.log(`matched url: ${requestConfig.url}`);
return extendConfig;
}
return null;
}
};
axios.defaults.withCredentials = true
axios.interceptors.request.use( function (request){
const token = localStorage.getItem('token')
const pandaPublish = localStorage.getItem('panda-publish')
const getWay = '/PandaCore/GateWay'
if(token){
request.headers.Authorization = 'Bearer ' + token
axios.defaults.withCredentials = true;
axios.interceptors.request.use(
function(request) {
const token = localStorage.getItem('token');
const pandaPublish = localStorage.getItem('panda-publish');
const getWay = '/PandaCore/GateWay';
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
if (pandaPublish) {
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) {
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) => {
},
);
axios.interceptors.response.use(
function(response) {
return response;
},
error => {
if (error.response) {
switch (error.response.status) {
case 401:
globalConfig.bizRedirectHandler(error.response)
globalConfig.bizRedirectHandler(error.response);
}
}
return Promise.reject(error);
})
},
);
export const request = (config, ctx) => {
const {
......@@ -106,7 +118,8 @@ export const request = (config, ctx) => {
requestOptions = bizRequestAdapter(requestOptions);
}
return axios(requestOptions).then(raw => raw && raw.data)
return axios(requestOptions)
.then(raw => raw && raw.data)
.then(
res =>
new Promise((resolve, reject) => {
......@@ -119,9 +132,7 @@ export const request = (config, ctx) => {
const errorDesc = bizDevErrorAdapter ? bizDevErrorAdapter(res) : null;
// 3. 用户级错误信息转换
const errorMsg = bizErrorMessageAdapter
? bizErrorMessageAdapter(res)
: null;
const errorMsg = bizErrorMessageAdapter ? bizErrorMessageAdapter(res) : null;
// 4. 成功信息转换
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