根据环境判断调用的接口地址
This commit is contained in:
parent
28da44a63b
commit
7dcc220b17
@ -1,6 +1,37 @@
|
|||||||
// const RequsetUrl = 'https://huishang.magicany.cc/api/v1'; // 请求地址前缀
|
// 环境配置
|
||||||
const RequsetUrl = 'https://test.hshuishang.com'; // 请求地址前缀
|
const environments = {
|
||||||
export const picUrl = 'https://test.hshuishang.com'; // 图片地址前缀
|
development: {
|
||||||
|
apiUrl: 'https://test.hshuishang.com',
|
||||||
|
picUrl: 'https://test.hshuishang.com'
|
||||||
|
},
|
||||||
|
production: {
|
||||||
|
apiUrl: 'https://huishang.magicany.cc/api/v1',
|
||||||
|
picUrl: 'https://huishang.magicany.cc/api/v1'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 判断当前环境
|
||||||
|
const getCurrentEnvironment = () => {
|
||||||
|
// 优先通过NODE_ENV判断
|
||||||
|
if (process && process.env && process.env.NODE_ENV) {
|
||||||
|
return process.env.NODE_ENV;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 通过全局配置判断(例如Vercel等平台的环境变量)
|
||||||
|
if (typeof global !== 'undefined' && global.env) {
|
||||||
|
return global.env;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 默认返回开发环境
|
||||||
|
return 'development';
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取当前环境配置
|
||||||
|
const currentEnv = getCurrentEnvironment();
|
||||||
|
const envConfig = environments[currentEnv] || environments.development;
|
||||||
|
|
||||||
|
export const RequsetUrl = envConfig.apiUrl; // 请求地址前缀
|
||||||
|
export const picUrl = envConfig.picUrl; // 图片地址前缀
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 小程序跳转方法二次封装
|
* @description 小程序跳转方法二次封装
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user