Commit 243664de by Jaxon

fix: 从环境变量读取配置中心地址,避免硬编码

1 parent b8d163a7
...@@ -115,11 +115,25 @@ Vue.directive("preventReClick", { ...@@ -115,11 +115,25 @@ Vue.directive("preventReClick", {
}); });
let baseConfig = config; let baseConfig = config;
// 如果要改地址, 优先去 .env.development 中配置
// 如果要创建自己的配置 可以 创建.env.development.local 文件. 该文件已被 git忽略, 不会上传, 优先级比.env.development更高, 满足本地开发的需求.
// 生产环境和测试环境用的都是 .env文件里面的内容. 不会串
// 这样配置, 不会再出现 改了地址 , 上传到git 甚至 上到测试环境 的情况
// 唯一需要注意的是, 改了 .env.development.local 文件的内容, 需要重新 npm run serve
/**
* 另: 在本地开发时,优先级是 .env.development.local > .env.development > .env.production > .env
* 以 VUE_APP_A 这个变量为例
* 如果 .env.development.local 文件没有, 就会取 .env.development 中的, 以此类推直到.env, 都没有 则返回 undefined
* 如果 所有 文件都有这个变量, 优先取 .env.development.local的
* 在生产环境中:
* 只取 .env.production .env 两个文件中的.
*/
const configCenterUrl = process.env.VUE_APP_CONFIG_CENTER_URL || "https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=dj-car-life-system-config";
console.log("configCenterUrl", configCenterUrl);
// 使用fetch 解决axios提前实例化导致sign里面的secret不能通过配置中心动态获取 // 使用fetch 解决axios提前实例化导致sign里面的secret不能通过配置中心动态获取
fetch( fetch(configCenterUrl).then(
"https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=dj-car-life-system-config",
)
.then(
(response) => { (response) => {
// 处理http响应 // 处理http响应
return response.json(); return response.json();
...@@ -128,8 +142,7 @@ fetch( ...@@ -128,8 +142,7 @@ fetch(
// 处理错误 // 处理错误
console.log(error); console.log(error);
}, },
) ).then((response) => {
.then((response) => {
const { code, data } = response; const { code, data } = response;
console.log("response", code, response); console.log("response", code, response);
if (code == "200") { if (code == "200") {
...@@ -163,10 +176,9 @@ fetch( ...@@ -163,10 +176,9 @@ fetch(
}); });
console.log(window.$gscApi, "========"); console.log(window.$gscApi, "========");
} }
}) }).finally(() => {
.finally(() => {
init(); init();
}); });
function init() { function init() {
new Vue({ new Vue({
router, router,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!