Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
npm
/
glsx-common
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 0b7ed9c9
authored
Sep 08, 2025
by
张立顺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat 白名单功能开发
1 parent
9a54ea77
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
2 deletions
api/ossConfigService.js
dist/glsx-common.js
package-lock.json
src/http.js
api/ossConfigService.js
0 → 100644
View file @
0b7ed9c
let
cachedWhiteUrl
=
null
/**
* 从配置服务获取OSS基础配置并返回 whiteUrl
* @returns {Promise<string>} whiteUrl 字符串
* @throws {Error} 当获取配置失败时抛出错误
*/
async
function
fetchWhiteUrl
()
{
// console.log(cachedWhiteUrl, 'cachedWhiteUrl')
// 如果已有缓存,直接返回
if
(
cachedWhiteUrl
)
{
return
cachedWhiteUrl
}
try
{
const
response
=
await
fetch
(
'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=glsx-common'
)
if
(
!
response
.
ok
)
{
throw
new
Error
(
'网络响应不是 OK'
)
}
const
result
=
await
response
.
json
()
cachedWhiteUrl
=
result
.
whiteUrl
// 缓存结果
cachedWhiteUrl
.
forEach
((
url
,
index
)
=>
{
cachedWhiteUrl
[
index
]
=
url
.
startsWith
(
'http:'
)
?
url
.
substring
(
5
)
:
url
})
console
.
log
(
'获取配置成功:'
,
cachedWhiteUrl
)
return
cachedWhiteUrl
}
catch
(
error
)
{
console
.
error
(
'获取配置失败:'
,
error
)
throw
error
}
}
// 直接导出异步获取 whiteUrl 的函数
export
default
fetchWhiteUrl
dist/glsx-common.js
View file @
0b7ed9c
This diff is collapsed.
Click to expand it.
package-lock.json
View file @
0b7ed9c
{
"name"
:
"glsx-common"
,
"version"
:
"2.1
.0
"
,
"version"
:
"2.1
0.1
"
,
"lockfileVersion"
:
1
,
"requires"
:
true
,
"dependencies"
:
{
...
...
src/http.js
View file @
0b7ed9c
...
...
@@ -7,6 +7,8 @@
import
util
from
'./util'
import
axios
from
'axios'
import
qs
from
'qs'
import
OssConfigService
from
'../api/ossConfigService'
// 导入配置服务
function
Http
(
options
=
{})
{
this
.
service
=
axios
.
create
({
withCredentials
:
true
,
...
...
@@ -25,10 +27,18 @@ function Http(options = {}) {
Object
.
assign
(
this
.
service
.
defaults
,
{
headers
:
Object
.
assign
({
'Content-Type'
:
'application/x-www-form-urlencoded; charset=UTF-8'
},
headers
)
},
{
baseURL
,
timeout
,
withCredentials
,
responseType
})
return
this
.
create
()
}
Http
.
prototype
.
create
=
function
()
{
this
.
service
.
interceptors
.
request
.
use
(
config
=>
{
async
config
=>
{
let
{
data
=
{},
sign
=
true
,
noSignAttr
=
[],
noSessionId
=
false
}
=
config
const
whiteUrl
=
await
OssConfigService
()
console
.
log
(
whiteUrl
,
'whiteUrl'
)
console
.
log
(
data
?.
method
,
'whiteUrl'
)
console
.
log
(
whiteUrl
.
includes
(
data
?.
method
))
if
(
whiteUrl
.
includes
(
data
?.
method
))
{
data
.
sdctag
=
true
}
if
(
!
noSessionId
)
{
data
.
sessionId
=
this
.
customer
.
sessionId
||
data
.
sessionId
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment