@gm-mobile/mp-request 3.10.2 → 3.11.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/config_private_domain.ts +45 -0
- package/src/index.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-mobile/mp-request",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.0-beta.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "zhongsink <zhongink@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/gmfe/gm-mobile#readme",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"url": "https://github.com/gmfe/gm-mobile/issues"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@gm-mobile/c-tool": "^3.
|
|
24
|
-
"@gm-mobile/locales": "^3.
|
|
25
|
-
"@gm-mobile/mp": "^3.
|
|
23
|
+
"@gm-mobile/c-tool": "^3.11.0-beta.0",
|
|
24
|
+
"@gm-mobile/locales": "^3.11.0-beta.0",
|
|
25
|
+
"@gm-mobile/mp": "^3.11.0-beta.0",
|
|
26
26
|
"js-base64": "^3.6.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"taro-axios": "^1.1.1",
|
|
31
31
|
"weapp-cookie": "^1.4.6"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "649f56a77dba3b7aeb46446d2fbef2338270ee8a"
|
|
34
34
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { get } from 'lodash'
|
|
2
|
+
import { instance } from './request'
|
|
3
|
+
import { axios } from 'taro-axios'
|
|
4
|
+
import { LocalStorage } from '@gm-mobile/mp'
|
|
5
|
+
|
|
6
|
+
// 如果有值使用此值作为接口请求域名
|
|
7
|
+
let privateBaseUrl: string = LocalStorage.get('privateBaseUrl') || ''
|
|
8
|
+
|
|
9
|
+
/** 私有化部署实现,监测到登录后,后续所有接口的请求域名将使用group中的private_domain字段值 */
|
|
10
|
+
async function configPrivateDomain(defaultBaseUrl: string) {
|
|
11
|
+
instance.interceptors.request.use(async (config) => {
|
|
12
|
+
const { baseURL = '', url, data = '{}' } = config
|
|
13
|
+
const fullUrl = baseURL + url
|
|
14
|
+
const apiName = fullUrl.split('/').reverse()[0]
|
|
15
|
+
const origin = fullUrl.split('/').slice(0, 3).join('/')
|
|
16
|
+
const form: any = /^\{/.test(data) ? JSON.parse(data) : {}
|
|
17
|
+
switch (apiName) {
|
|
18
|
+
case 'Token': {
|
|
19
|
+
const group_id = form.group_id
|
|
20
|
+
const group_customized_code = form.group_customized_code
|
|
21
|
+
const {
|
|
22
|
+
data: { groups },
|
|
23
|
+
status,
|
|
24
|
+
} = await axios.post(
|
|
25
|
+
'/ceres/enterprise/EnterpriseService/ListLoginGroup',
|
|
26
|
+
{
|
|
27
|
+
group_id,
|
|
28
|
+
customized_code: group_customized_code,
|
|
29
|
+
},
|
|
30
|
+
{ baseURL: defaultBaseUrl }
|
|
31
|
+
)
|
|
32
|
+
if (status !== 200)
|
|
33
|
+
return Promise.reject(new Error('ListLoginGroup 请求失败'))
|
|
34
|
+
privateBaseUrl = get(groups, '0.private_domain_name') || ''
|
|
35
|
+
LocalStorage.set('privateBaseUrl', privateBaseUrl)
|
|
36
|
+
break
|
|
37
|
+
}
|
|
38
|
+
default:
|
|
39
|
+
}
|
|
40
|
+
config.baseURL = privateBaseUrl || defaultBaseUrl
|
|
41
|
+
return Promise.resolve(config)
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default configPrivateDomain
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import configHeaders from './config_headers'
|
|
|
4
4
|
import configTrace from './config_trace'
|
|
5
5
|
import configError from './config_error'
|
|
6
6
|
import configProgress from './config_progress'
|
|
7
|
+
import configPrivateDomain from './config_private_domain'
|
|
7
8
|
import { initAuth, clearAuth, setAccessToken } from './init'
|
|
8
9
|
|
|
9
10
|
export {
|
|
@@ -16,5 +17,6 @@ export {
|
|
|
16
17
|
configError,
|
|
17
18
|
configProgress,
|
|
18
19
|
setAccessToken,
|
|
20
|
+
configPrivateDomain,
|
|
19
21
|
}
|
|
20
22
|
export type { Response } from './types'
|