家谱现有接口调试50%
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
(function (root, factory) {
|
||||
// 全局配置同时支持浏览器页面和 Node 测试。
|
||||
if (typeof module === 'object' && module.exports) {
|
||||
module.exports = factory;
|
||||
return;
|
||||
}
|
||||
|
||||
root.GenealogyConfig = factory(root);
|
||||
})(typeof globalThis !== 'undefined' ? globalThis : window, function (root) {
|
||||
'use strict';
|
||||
|
||||
var DEFAULT_ENV = 'development';
|
||||
var API_BASE_URLS = {
|
||||
development: 'http://test-genealogy-api.ddxcjp.cn',
|
||||
production: ''
|
||||
};
|
||||
var TEST_API_HTTP_URL = 'http://test-genealogy-api.ddxcjp.cn';
|
||||
var TEST_API_HTTPS_URL = 'https://test-genealogy-api.ddxcjp.cn';
|
||||
var CLIENT_ID = 'ced7e5f0498645c6ec642dcf450b036f';
|
||||
var TENANT_ID = '000000';
|
||||
var TOKEN_KEY = 'genealogy_auth_token';
|
||||
var TOKEN_HEADER_NAME = 'Authorization';
|
||||
var ENV_KEY = 'genealogy_env';
|
||||
var BASE_URL_KEY = 'genealogy_api_base_url';
|
||||
|
||||
function readStorage(key) {
|
||||
try {
|
||||
return root.localStorage && root.localStorage.getItem(key);
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function getEnv() {
|
||||
return readStorage(ENV_KEY) || DEFAULT_ENV;
|
||||
}
|
||||
|
||||
function normalizeApiBaseUrl(value) {
|
||||
// 测试域名当前 HTTPS 握手失败,开发环境统一走可访问的 HTTP 地址。
|
||||
var url = String(value || '').replace(/\/+$/, '');
|
||||
|
||||
if (url === TEST_API_HTTPS_URL) return TEST_API_HTTP_URL;
|
||||
return url;
|
||||
}
|
||||
|
||||
function getApiBaseUrl() {
|
||||
return normalizeApiBaseUrl(readStorage(BASE_URL_KEY) || API_BASE_URLS[getEnv()] || API_BASE_URLS.development);
|
||||
}
|
||||
|
||||
function getConfig() {
|
||||
return {
|
||||
env: getEnv(),
|
||||
apiBaseUrl: getApiBaseUrl(),
|
||||
clientId: CLIENT_ID,
|
||||
tenantId: TENANT_ID,
|
||||
tokenKey: TOKEN_KEY,
|
||||
tokenHeaderName: TOKEN_HEADER_NAME
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
getConfig: getConfig,
|
||||
getApiBaseUrl: getApiBaseUrl,
|
||||
getClientId: function () {
|
||||
return CLIENT_ID;
|
||||
},
|
||||
getTenantId: function () {
|
||||
return TENANT_ID;
|
||||
},
|
||||
getTokenKey: function () {
|
||||
return TOKEN_KEY;
|
||||
},
|
||||
getTokenHeaderName: function () {
|
||||
return TOKEN_HEADER_NAME;
|
||||
}
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user