Commit 077afdfc by Chao Sun

test反向代理

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