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.

feat: support for parametrizing the base path #335 #836 #800

shuai53ba7fb0355f
diff --cc ui/.env.production
index 33d84710,5e1007e7..3d8f6a77
--- a/ui/.env.production
+++ b/ui/.env.production
@@@ -1,4 -1,5 +1,5 @@@
TSC_COMPILE_ON_ERROR=true
ESLINT_NO_DEV_ERRORS=true
--PUBLIC_URL = /
--REACT_APP_API_URL = /
-REACT_APP_BASE_URL = ""
++PUBLIC_URL=/
++REACT_APP_API_URL=/
++REACT_APP_BASE_URL=/test
diff --cc ui/package.json
index 63a1f85d,e10d6e7c..86e34c1e
--- a/ui/package.json
+++ b/ui/package.json
@@@ -2,10 -2,10 +2,10 @@@
"name": "answer-static",
"version": "0.1.0",
"private": true,
- "homepage": "/test",
+ "homepage": "/",
"scripts": {
"start": "react-app-rewired start",
-- "build": "react-app-rewired build",
++ "build": "node ./scripts/env.js && react-app-rewired build",
"lint": "eslint . --cache --fix --ext .ts,.tsx",
"prettier": "prettier --write 'src/**/*.{js,jsx,ts,tsx,json,css,scss,md}' --config ./.prettierrc.json",
"pre-install": "node ./scripts/preinstall.js && pnpm install",
@@@ -76,6 -76,6 +76,7 @@@
"eslint-plugin-react-hooks": "^4.6.0",
"humps": "^2.0.1",
"husky": "^8.0.1",
++ "js-yaml": "^4.1.0",
"lint-staged": "^13.2.3",
"postcss": "^8.0.0",
"prettier": "^3.1.0",
diff --cc ui/pnpm-lock.yaml
index 0369458a,83bdc9e2..18092545
--- a/ui/pnpm-lock.yaml
+++ b/ui/pnpm-lock.yaml
@@@ -200,6 -183,6 +183,9 @@@ importers
husky:
specifier: ^8.0.1
version: 8.0.1
++ js-yaml:
++ specifier: ^4.1.0
++ version: 4.1.0
lint-staged:
specifier: ^13.2.3
version: 13.3.0
@@@ -231,6 -214,6 +217,64 @@@
specifier: ^0.8.0
version: 0.8.0
++ src/plugins/captcha-basic:
++ devDependencies:
++ '@typescript-eslint/eslint-plugin':
++ specifier: ^6.0.0
++ version: 6.11.0(@typescript-eslint/[email protected])([email protected])([email protected])
++ '@typescript-eslint/parser':
++ specifier: ^6.0.0
++ '@vitejs/plugin-react-swc':
++ specifier: ^3.3.2
++ version: 3.5.0([email protected])
++ eslint:
++ specifier: ^8.45.0
++ version: 8.53.0
++ eslint-plugin-react-hooks:
++ specifier: ^4.6.0
++ version: 4.6.0([email protected])
++ eslint-plugin-react-refresh:
++ specifier: ^0.4.3
++ version: 0.4.5([email protected])
++ typescript:
++ specifier: ^5.0.2
++ version: 5.3.2
++ vite:
++ specifier: ^4.4.5
++ version: 4.5.0(@types/[email protected])([email protected])
++
++ src/plugins/captcha-google-v2:
++ dependencies:
++ react-google-recaptcha:
++ specifier: ^3.1.0
++ version: 3.1.0([email protected])
++ devDependencies:
++ '@typescript-eslint/eslint-plugin':
++ specifier: ^6.0.0
++ version: 6.11.0(@typescript-eslint/[email protected])([email protected])([email protected])
++ '@typescript-eslint/parser':
++ specifier: ^6.0.0
++ '@vitejs/plugin-react-swc':
++ specifier: ^3.3.2
++ version: 3.5.0([email protected])
++ eslint:
++ specifier: ^8.45.0
++ version: 8.53.0
++ eslint-plugin-react-hooks:
++ specifier: ^4.6.0
++ version: 4.6.0([email protected])
++ eslint-plugin-react-refresh:
++ specifier: ^0.4.3
++ version: 0.4.5([email protected])
++ typescript:
++ specifier: ^5.0.2
++ version: 5.3.2
++ vite:
++ specifier: ^4.4.5
++ version: 4.5.0(@types/[email protected])([email protected])
++
src/plugins/editor-chart:
dependencies:
mermaid:
@@@ -3072,7 -3055,7 +3116,7 @@@ packages
resolution: {integrity: sha512-/fqTbjxyFUaYNO7VcW5g+4npmqVACz1bB7RTHYuLj+PRjw9hrCwrUXVQFpChUS0JsyEFvMZ7U/PfmvWgxJhI9g==}
dependencies:
'@types/estree': 1.0.0
-- '@types/json-schema': 7.0.13
++ '@types/json-schema': 7.0.15
resolution: {integrity: sha512-uQDwm1wFHmbBbCZCqAlq6Do9LYwByNZHWzXppSnay9SuwJ+VRbjkbLABer54kcPnMSlG6Fdiy2yaFXm/z9Z5gw==}
@@@ -3149,12 -3132,12 +3193,8 @@@
pretty-format: 27.5.1
dev: true
-- /@types/[email protected]:
-- resolution: {integrity: sha512-RbSSoHliUbnXj3ny0CNFOoxrIDV6SUGyStHsvDqosw6CkdPV8TtWGlfecuK4ToyMEAql6pzNxgCFKanovUzlgQ==}
--
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
-- dev: true
resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==}
@@@ -3594,7 -3577,7 +3634,7 @@@
peerDependencies:
eslint: ^6.0.0 || ^7.0.0 || ^8.0.0
dependencies:
-- '@types/json-schema': 7.0.13
++ '@types/json-schema': 7.0.15
'@typescript-eslint/scope-manager': 5.38.0
'@typescript-eslint/types': 5.38.0
'@typescript-eslint/typescript-estree': 5.38.0([email protected])
@@@ -3612,7 -3595,7 +3652,7 @@@
eslint: ^7.0.0 || ^8.0.0
dependencies:
'@eslint-community/eslint-utils': 4.4.0([email protected])
-- '@types/json-schema': 7.0.13
++ '@types/json-schema': 7.0.15
'@types/semver': 7.5.5
'@typescript-eslint/scope-manager': 6.11.0
'@typescript-eslint/types': 6.11.0
@@@ -3631,7 -3614,7 +3671,7 @@@
eslint: ^7.0.0 || ^8.0.0
dependencies:
'@eslint-community/eslint-utils': 4.4.0([email protected])
-- '@types/json-schema': 7.0.13
++ '@types/json-schema': 7.0.15
'@types/semver': 7.5.5
'@typescript-eslint/scope-manager': 6.11.0
'@typescript-eslint/types': 6.11.0
@@@ -3950,7 -3933,7 +3990,6 @@@
resolution: {integrity: sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==}
engines: {node: '>=0.4.0'}
hasBin: true
-- dev: true
resolution: {integrity: sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==}
@@@ -6954,7 -6937,7 +6993,7 @@@
optional: true
dependencies:
'@babel/code-frame': 7.18.6
-- '@types/json-schema': 7.0.13
++ '@types/json-schema': 7.0.15
chalk: 4.1.2
chokidar: 3.5.3
cosmiconfig: 6.0.0
@@@ -7262,6 -7245,6 +7301,12 @@@
resolution: {integrity: sha512-2bsegYkkHO+h/9MGbn6KWcE45cHZgPANo5LXF7EvWdT0yT2EguSVO1nDgU5c8+ZOPwp2vMNa7YFsJhVcDR9Sdg==}
dev: false
++ resolution: {integrity: sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==}
++ dependencies:
++ react-is: 16.13.1
++ dev: false
++
resolution: {integrity: sha512-HRcs+2mr52W0K+x8RzcLzuPPmVIKMSv97RGHy0Ea9y/mpcaK+xTrjICA04KAHi4GRzxliNqNJEFYWHghy3rSfQ==}
engines: {node: '>= 6.0.0'}
@@@ -8421,7 -8404,7 +8466,7 @@@
optional: true
dependencies:
abab: 2.0.6
-- acorn: 8.10.0
++ acorn: 8.11.3
acorn-globals: 6.0.0
cssom: 0.4.4
cssstyle: 2.3.0
@@@ -10282,6 -10265,6 +10327,16 @@@
semver: 5.7.1
dev: true
++ resolution: {integrity: sha512-bCpkbm9JiAuMGhkqoAiC0lLkb40DJ0HOEJIku+9JDjxX3Rcs+ztEOG13wbrOskt3n2DTrjshhaQ/iay+SnGg5Q==}
++ peerDependencies:
++ react: '>=16.4.1'
++ dependencies:
++ hoist-non-react-statics: 3.3.2
++ prop-types: 15.8.1
++ react: 18.2.0
++ dev: false
++
resolution: {integrity: sha512-87gRP69VAfeU2yKgp8RI3HvzhPNrnYIV2QNranYXataz3ef+k7OhvKGGdxQLQfUsQ2RTmlY66tn4pdFrZ94hNg==}
peerDependencies:
@@@ -10366,6 -10349,6 +10421,16 @@@
resolution: {integrity: sha512-rtGImPZ0YyLrscKI9xTpV8psd6I8VAtjKCzQDlzyDvqJA8XOW78TXYQwNRNd8g8JZnDu8q9Fu/1v4HPAVwVdHA==}
dev: false
++ resolution: {integrity: sha512-cYW2/DWas8nEKZGD7SCu9BSuVz8iOcOLHChHyi7upUuVhkpkhYG/6N3KDiTQ3XAiZ2UAZkfvYKMfAHOzBOcGEg==}
++ peerDependencies:
++ react: '>=16.4.1'
++ dependencies:
++ prop-types: 15.8.1
++ react: 18.2.0
++ react-async-script: 1.2.0([email protected])
++ dev: false
++
resolution: {integrity: sha512-9jZ57/dAn9t3q6hneQS0wukqC2ENOBgMNVEhb/ZG9ZSxUetzVIw4iAmEU38IaVg3QGYauQPhSeUTuIUtFglWpg==}
peerDependencies:
@@@ -10947,7 -10930,7 +11012,7 @@@
resolution: {integrity: sha512-0ilKFI6QQF5nxDZLFn2dMjvc4hjg/Wkg7rHd3jK6/A4a1Hl9VFdQWvgB1UMGoU94pad1P/8N7fMcEnLnSiju8A==}
engines: {node: '>= 8.9.0'}
dependencies:
-- '@types/json-schema': 7.0.13
++ '@types/json-schema': 7.0.15
ajv: 6.12.6
ajv-keywords: 3.5.2([email protected])
@@@ -10955,7 -10938,7 +11020,7 @@@
resolution: {integrity: sha512-SHiNtMOUGWBQJwzISiVYKu82GiV4QYGePp3odlY1tuKO7gPtphAT5R/py0fA6xtbgLL/RvtJZnU9b8s0F1q0Xg==}
engines: {node: '>= 8.9.0'}
dependencies:
-- '@types/json-schema': 7.0.13
++ '@types/json-schema': 7.0.15
ajv: 6.12.6
ajv-keywords: 3.5.2([email protected])
@@@ -10963,7 -10946,7 +11028,7 @@@
resolution: {integrity: sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw==}
engines: {node: '>= 10.13.0'}
dependencies:
-- '@types/json-schema': 7.0.13
++ '@types/json-schema': 7.0.15
ajv: 6.12.6
ajv-keywords: 3.5.2([email protected])
@@@ -10980,7 -10963,7 +11045,7 @@@
resolution: {integrity: sha512-1edyXKgh6XnJsJSQ8mKWXnN/BVaIbFMLpouRUrXgVq7WYne5kw3MW7UPhO44uRXQSIpTSXoJbmrR2X0w9kUTyg==}
engines: {node: '>= 12.13.0'}
dependencies:
-- '@types/json-schema': 7.0.13
++ '@types/json-schema': 7.0.15
ajv: 8.11.0
ajv-formats: 2.1.1([email protected])
ajv-keywords: 5.1.0([email protected])
@@@ -11713,7 -11696,7 +11778,7 @@@
hasBin: true
dependencies:
'@jridgewell/source-map': 0.3.2
-- acorn: 8.10.0
++ acorn: 8.11.3
commander: 2.20.3
source-map-support: 0.5.21
diff --cc ui/scripts/env.js
index 00000000,00000000..df97966c
new file mode 100644
--- /dev/null
+++ b/ui/scripts/env.js
@@@ -1,0 -1,0 +1,21 @@@
++const fs = require('fs');
++const path = require('path');
++const yaml = require('js-yaml');
++
++const configFilePath = path.resolve(__dirname, '../../configs/config.yaml');
++const envFilePath = path.resolve(__dirname, '../.env.production');
++
++// Read config.yaml file
++const config = yaml.load(fs.readFileSync(configFilePath, 'utf8'));
++
++// Generate .env file content
++let envContent = 'TSC_COMPILE_ON_ERROR=true\nESLINT_NO_DEV_ERRORS=true\n';
++for (const key in config.ui) {
++ const value = config.ui[key];
++ envContent += `${key.toUpperCase()}=${value}\n`;
++}
++
++// Write .env file
++fs.writeFileSync(envFilePath, envContent);
++
++console.log(`Generated ${envFilePath}`);
diff --cc ui/src/router/alias.ts
index 5a155969,5f765b22..21a466c0
--- a/ui/src/router/alias.ts
+++ b/ui/src/router/alias.ts
@@@ -16,6 -16,10 +16,8 @@@
* specific language governing permissions and limitations
* under the License.
*/
-
+ export const REACT_BASE_PATH = process.env.REACT_APP_BASE_URL || '';
-
+ export const BASE_ORIGIN = `${window.location.origin}${REACT_BASE_PATH}`;
export const RouteAlias = {
home: '/',