Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sfp-program
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sweet Zhang
sfp-program
Commits
077afdfc
Commit
077afdfc
authored
Sep 01, 2022
by
Chao Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test反向代理
parent
d445da23
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
17 deletions
+17
-17
manifest.json
+14
-14
util/interceptor.ts
+3
-3
No files found.
manifest.json
View file @
077afdfc
...
...
@@ -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"
:
""
}
}
}
//
}
}
}
util/interceptor.ts
View file @
077afdfc
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
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment