Commit d0413344 by 李伟康

feat(config): 添加环境配置支持

- 新增环境映射对象,支持 develop、test、production 和 beta 环境
- 实现 hasEnv 配置选项,允许在请求 URL 中动态添加环境参数
- 修改配置获取逻辑,根据环境配置动态构建请求地址
- 更新 SDK 版本号从 0.1.6 到 0.1.7
1 parent eaa468e7
{
"name": "glsk-mapapi-sdk",
"version": "0.1.6",
"version": "0.1.7",
"type": "module",
"description": "glsk-mapapi-sdk",
"main": "src/index.js",
......
const envObject = {
1: 'develop',
2: 'test',
3: 'production',
4: 'beta'
}
class GlMapSdk {
constructor() {
let mapConfig = {
......@@ -14,7 +20,9 @@ class GlMapSdk {
if (typeof window !== 'undefined') {
const fetchConfig = async () => {
try {
const response = await fetch(`https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=map-api-js`);
let url = 'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=map-api-js'
if(mapConfig.hasEnv) url += `&env=${envObject[mapConfig.env]}`;
const response = await fetch(url);
const res = await response.json(),
scriptExists = Array.from(document.head.getElementsByTagName('script')).some(script => script.src === res.apiUrl);
if (!scriptExists) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!