From cbaa872a292c50e4de755a40953efc468915c43a Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Tue, 4 Oct 2022 19:52:46 +0800 Subject: [PATCH] chore: remove local fe config --- client/web/assets/config.json | 3 --- client/web/build/webpack.config.ts | 6 +----- client/web/scripts/sync-config-from-env.js | 20 ----------------- client/web/src/init.tsx | 25 ++++------------------ 4 files changed, 5 insertions(+), 49 deletions(-) delete mode 100644 client/web/assets/config.json delete mode 100644 client/web/scripts/sync-config-from-env.js diff --git a/client/web/assets/config.json b/client/web/assets/config.json deleted file mode 100644 index 51a53d0c..00000000 --- a/client/web/assets/config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "serviceUrl": null -} diff --git a/client/web/build/webpack.config.ts b/client/web/build/webpack.config.ts index 4a894bd3..4f5e7754 100644 --- a/client/web/build/webpack.config.ts +++ b/client/web/build/webpack.config.ts @@ -76,10 +76,6 @@ const plugins: Configuration['plugins'] = [ from: path.resolve(ROOT_PATH, './assets/pwa.webmanifest'), to: 'pwa.webmanifest', }, - { - from: path.resolve(ROOT_PATH, './assets/config.json'), - to: 'config.json', - }, { from: path.resolve(ROOT_PATH, './assets/images/logo/'), to: 'images/logo/', @@ -103,7 +99,7 @@ const plugins: Configuration['plugins'] = [ skipWaiting: true, // Do not precache images - exclude: [/\.(?:png|jpg|jpeg|svg)$/, 'config.json'], + exclude: [/\.(?:png|jpg|jpeg|svg)$/], maximumFileSizeToCacheInBytes: 8 * 1024 * 1024, // 限制最大缓存 8M diff --git a/client/web/scripts/sync-config-from-env.js b/client/web/scripts/sync-config-from-env.js deleted file mode 100644 index 8d6f3e1b..00000000 --- a/client/web/scripts/sync-config-from-env.js +++ /dev/null @@ -1,20 +0,0 @@ -/** - * 用于 dockerfile 启动命令 - * 将环境变量的信息同步到 dist/config.json 文件中 - */ - -const fs = require('fs-extra'); -const path = require('path'); - -const envConfig = require('../assets/config.json'); // 获取默认配置 - -if (process.env.SERVICE_URL) { - envConfig.serviceUrl = process.env.SERVICE_URL; -} - -if (envConfig) { - fs.writeJsonSync(path.resolve(__dirname, '../dist/config.json'), envConfig, { - spaces: 2, - }); - console.log('从环境变量更新config完毕:', envConfig); -} diff --git a/client/web/src/init.tsx b/client/web/src/init.tsx index db491006..beac29d3 100644 --- a/client/web/src/init.tsx +++ b/client/web/src/init.tsx @@ -107,24 +107,7 @@ setErrorHook((err) => { /** * 获取前端配置 */ -request - .get('/config.json?v2', { - baseURL: '', - }) - .then(({ data: config }) => { - if (!localStorageServiceUrl && isValidStr(_get(config, 'serviceUrl'))) { - // 配置的优先级低于localStorage的优先级 - setServiceUrl(() => _get(config, 'serviceUrl')); - } - }) - .catch(() => {}) - .finally(() => { - /** - * 初始化时加载全局配置 - * 确保在请求前端配置之后(即尝试通过配置文件修改地址之后)再发起请求 - */ - fetchGlobalConfig().catch((e) => { - showErrorToasts(t('全局配置加载失败')); - console.error('全局配置加载失败', e); - }); - }); +fetchGlobalConfig().catch((e) => { + showErrorToasts(t('全局配置加载失败')); + console.error('全局配置加载失败', e); +});