Commit 077afdfc by Chao Sun

test反向代理

parent d445da23
......@@ -73,7 +73,7 @@
"router" : {
"base" : "/sfp/",
"mode" : "hash"
}
},
// "devServer": {
// "/api":{
// "target":"https://mdev.zuihuibi.cn",
......@@ -82,19 +82,19 @@
// "logLevel":"debug",
// "pathRewrite":{"^/proxy":""}
// },
// // "port": 3001, // 端口号
// // "disableHostCheck": true,
// // "proxy": {
// // "/api": {
// // "target": "https://mdev.zuihuibi.cn", //请求的目标域名
// // "changeOrigin": true, //是否跨域
// // "secure": false //设置支持https协议的代理
// // "pathRewrite": { //匹配请求路径里面有 /api 会替换成https://mdev.zuihuibi.cn
// // // 举例:/api/api/user => https://mdev.zuihuibi.cn/api/user
// // "^/api": ""
// // }
// // }
// // }
"port": 3001, // 端口号
"disableHostCheck": true,
"proxy": {
"/api": {
"target": "https://mdev.zuihuibi.cn", //请求的目标域名
"changeOrigin": true, //是否跨域
"secure": false, //设置支持https协议的代理
"pathRewrite": { //匹配请求路径里面有 /api 会替换成https://mdev.zuihuibi.cn
// 举例:/api/api/user => https://mdev.zuihuibi.cn/api/user
"^/api": ""
}
}
}
// }
}
}
import api from "../api/api";
import {baseURL,apiURL,sfpURL} from "../environments/environment";
// 白名单,不需要携带token就允许被访问的接口
const whiteApiList = ['https://mdev.zuihuibi.cn/api/authorize/obtainToken']
const whiteApiList = [`${baseURL}/api/authorize/obtainToken`]
export const interceptor = () => {
......@@ -15,12 +15,12 @@ export const interceptor = () => {
uni.showLoading({
title: '加载中...'
})
console.log(!whiteApiList.includes(args.url))
// 当本地没有token,并且接口地址没在白名单内,需要重新获取token
if (!uni.getStorageSync('uni-token') && !whiteApiList.includes(args.url)) {
return new Promise((resolve, reject)=>{
uni.request({
url:'https://mdev.zuihuibi.cn/api/authorize/obtainToken',
url: baseURL + '/api/authorize/obtainToken',
method:'POST',
data:{ticket: 'uni-app'},
success: (res) => {
......
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