Commit 943d0e34 by 张立顺

Merge branch 'v1.0.0' into 'v1.0.1'

feat 白名单功能开发

See merge request !1
2 parents 9a54ea77 0b7ed9c9
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
{
"name": "glsx-common",
"version": "2.1.0",
"version": "2.10.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
......@@ -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
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!