Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

refactor(env): migrate env config by .env file

haitao(lj)424f97f53909
diff --git a/ui/.env b/ui/.env
deleted file mode 100644
index 6893217c..00000000
--- a/ui/.env
+++ /dev/null
@@ -1 +0,0 @@
-PUBLIC_URL=
diff --git a/ui/.env.development b/ui/.env.development
index 8648d82a..c78ae289 100644
--- a/ui/.env.development
+++ b/ui/.env.development
@@ -1 +1,2 @@
-REACT_APP_API_URL=http://10.0.10.98:2060
+PUBLIC_URL
+REACT_APP_API_URL = http://127.0.0.1
diff --git a/ui/.env.production b/ui/.env.production
index 940bd4a8..e04b4d35 100644
--- a/ui/.env.production
+++ b/ui/.env.production
@@ -1,3 +1,2 @@
-REACT_APP_API_URL=/
-REACT_APP_PUBLIC_PATH=/
-REACT_APP_VERSION=
+PUBLIC_URL = /
+REACT_APP_API_URL = /
diff --git a/ui/.env.test b/ui/.env.test
deleted file mode 100644
index e69de29b..00000000
diff --git a/ui/.gitignore b/ui/.gitignore
index c4796f76..fe3fdef0 100644
--- a/ui/.gitignore
+++ b/ui/.gitignore
@@ -13,10 +13,7 @@
# misc
.DS_Store
-.env.local
-.env.development.local
-.env.test.local
-.env.production.local
+.env*.local
npm-debug.log*
yarn-debug.log*
diff --git a/ui/.gitlab-ci.yml b/ui/.gitlab-ci.yml
deleted file mode 100644
index df03dd15..00000000
--- a/ui/.gitlab-ci.yml
+++ /dev/null
@@ -1,93 +0,0 @@
-include:
- - project: 'segmentfault/devops/templates'
- file:
- - .deploy-cdn.yml
- - .deploy-helm.yml
-
-variables:
- FF_USE_FASTZIP: 'true'
- PROJECT_NAME: 'answer_static'
-
-stages:
- - install
- - publish
- - deploy
-
-# 静态资源构建
-install:
- image: dockerhub.qingcloud.com/sf_base/node-build:14
- stage: install
- allow_failure: false
-
- cache:
- - key:
- files:
- - pnpm-lock.yml
- paths:
- - node_modules/
- policy: pull-push
- script:
- - pnpm install
- - if [ "$CI_COMMIT_BRANCH" = "dev" ]; then
- sed -i "s/<projectName>/$PROJECT_NAME/g" .env.development;
- sed -i "s/<version>/$CI_COMMIT_SHORT_SHA/g" .env.development;
- pnpm run build:dev;
- elif [ "$CI_COMMIT_BRANCH" = "main" ]; then
- sed -i "s/<projectName>/$PROJECT_NAME/g" .env.test;
- sed -i "s/<version>/$CI_COMMIT_SHORT_SHA/g" .env.test;
- pnpm run build:test;
- elif [ "$CI_COMMIT_BRANCH" = "release" ]; then
- sed -i "s/<projectName>/$PROJECT_NAME/g" .env.production;
- sed -i "s/<version>/$CI_COMMIT_SHORT_SHA/g" .env.production;
- pnpm run build:prod;
- fi
- artifacts:
- paths:
- - build/
-
-publish:cdn:dev:
- extends: .deploy-cdn
- stage: publish
- only:
- - dev
- variables:
- AssetsPath: ./build
- Project: $PROJECT_NAME
- Version: $CI_COMMIT_SHORT_SHA
- Destination: dev
-
-publish:cdn:test:
- extends: .deploy-cdn
- stage: publish
- only:
- - main
- variables:
- AssetsPath: ./build
- Project: $PROJECT_NAME
- Version: $CI_COMMIT_SHORT_SHA
- Destination: test
-
-publish:cdn:prod:
- extends: .deploy-cdn
- stage: publish
- only:
- - release
- variables:
- AssetsPath: ./build
- Project: $PROJECT_NAME
- Version: $CI_COMMIT_SHORT_SHA
- Destination: prod
-
-deploy:dev:
- extends: .deploy-helm
- stage: deploy
- only:
- - dev
- needs:
- - publish:cdn:dev
- variables:
- KubernetesCluster: dev
- KubernetesNamespace: 'sf-test'
- DockerTag: $CI_COMMIT_SHORT_SHA
- ChartName: answer-web
- InstallPolicy: replace
diff --git a/ui/config-overrides.js b/ui/config-overrides.js
index e8d2dceb..f1bec311 100644
--- a/ui/config-overrides.js
+++ b/ui/config-overrides.js
@@ -4,7 +4,6 @@ const i18nLocaleTool = require('./scripts/i18n-locale-tool');
module.exports = {
webpack: function (config, env) {
if (env === 'production') {
- config.output.publicPath = process.env.REACT_APP_PUBLIC_PATH;
i18nLocaleTool.resolvePresetLocales();
}
@@ -33,12 +32,12 @@ module.exports = {
const config = configFunction(proxy, allowedHost);
config.proxy = {
'/answer': {
- target: 'http://10.0.10.98:2060',
+ target: process.env.REACT_APP_API_URL,
changeOrigin: true,
secure: false,
},
'/installation': {
- target: 'http://10.0.10.98:2060',
+ target: process.env.REACT_APP_API_URL,
changeOrigin: true,
secure: false,
},
diff --git a/ui/package.json b/ui/package.json
index fd2a3470..97759d93 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -5,11 +5,7 @@
"homepage": "/",
"scripts": {
"start": "react-app-rewired start",
- "build:dev": "env-cmd -f .env.development react-app-rewired build",
- "build:test": "env-cmd -f .env.test react-app-rewired build",
- "build:prod": "env-cmd -f .env.production react-app-rewired build",
- "build": "env-cmd -f .env react-app-rewired build",
- "test": "react-app-rewired test",
+ "build": "react-app-rewired build",
"lint": "eslint . --cache --fix --ext .ts,.tsx",
"prepare": "cd .. && husky install",
"cz": "cz",
diff --git a/ui/src/utils/request.ts b/ui/src/utils/request.ts
index 7859b90d..c58af99c 100644
--- a/ui/src/utils/request.ts
+++ b/ui/src/utils/request.ts
@@ -10,16 +10,8 @@ import { getCurrentLang } from '@/utils/localize';
import Storage from './storage';
import { floppyNavigation } from './floppyNavigation';
-const API = {
- development: '',
- production: '',
- test: '',
-};
-
-const baseApiUrl = process.env.REACT_APP_API_URL || API[process.env.NODE_ENV];
-
const baseConfig = {
- baseUrl: baseApiUrl,
+ baseUrl: process.env.REACT_APP_API_URL || '',
timeout: 10000,
withCredentials: true,
};