From 2a41f64d1b38dc2be304e2128a94eec23383c560 Mon Sep 17 00:00:00 2001 From: whyour Date: Fri, 29 Sep 2023 16:07:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20QlBaseUrl=20=E6=9C=AB?= =?UTF-8?q?=E5=B0=BE=E4=B8=8D=E5=8A=A0=E6=96=9C=E6=9D=A0=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-en.md | 4 ++-- README.md | 4 ++-- back/app.ts | 1 - back/config/serverEnv.ts | 8 ++++++++ shell/share.sh | 10 ++++++++++ src/layouts/index.tsx | 2 +- tsconfig.json | 11 ++--------- 7 files changed, 25 insertions(+), 15 deletions(-) diff --git a/README-en.md b/README-en.md index fc8dace7..ce6a3d16 100644 --- a/README-en.md +++ b/README-en.md @@ -63,7 +63,7 @@ docker run -dit \ -v $PWD/ql/data:/ql/data \ # The 5700 after the colon is the default port, if QlPort is set, it needs to be the same as QlPort. -p 5700:5700 \ - # Deployment paths are not required and begin and end with a slash, e.g. /test/. + # Deployment paths are not required, e.g. /test. -e QlBaseUrl="/" \ # Deployment port is not required, when using host mode, you can set the port after service startup, default 5700 -e QlPort="5700" \ @@ -95,7 +95,7 @@ podman run -dit \ -v $PWD/ql/data:/ql/data \ # The 5700 after the colon is the default port, if QlPort is set, it needs to be the same as QlPort. -p 5700:5700 \ - # Deployment paths are not required and begin and end with a slash, e.g. /test/. + # Deployment paths are not required, e.g. /test. -e QlBaseUrl="/" \ # Deployment port is not required, when using host mode, you can set the port after service startup, default 5700 -e QlPort="5700" \ diff --git a/README.md b/README.md index 697ae4e0..195f5287 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ docker run -dit \ -v $PWD/ql/data:/ql/data \ # 冒号后面的 5700 为默认端口,如果设置了 QlPort, 需要跟 QlPort 保持一致 -p 5700:5700 \ - # 部署路径非必须,以斜杠开头和结尾,比如 /test/ + # 部署路径非必须,比如 /test -e QlBaseUrl="/" \ # 部署端口非必须,当使用 host 模式时,可以设置服务启动后的端口,默认 5700 -e QlPort="5700" \ @@ -97,7 +97,7 @@ podman run -dit \ -v $PWD/ql/data:/ql/data \ # 冒号后面的 5700 为默认端口,如果设置了 QlPort, 需要跟 QlPort 保持一致 -p 5700:5700 \ - # 部署路径非必须,以斜杠开头和结尾,比如 /test/ + # 部署路径非必须,比如 /test -e QlBaseUrl="/" \ # 部署端口非必须,当使用 host 模式时,可以设置服务启动后的端口,默认 5700 -e QlPort="5700" \ diff --git a/back/app.ts b/back/app.ts index 8e6ae90a..c0341973 100644 --- a/back/app.ts +++ b/back/app.ts @@ -2,7 +2,6 @@ import 'reflect-metadata'; // We need this in order to use @Decorators import config from './config'; import express from 'express'; import Logger from './loaders/logger'; -import path from 'path'; async function startServer() { const app = express(); diff --git a/back/config/serverEnv.ts b/back/config/serverEnv.ts index bbb9fc15..1f9d5e0d 100644 --- a/back/config/serverEnv.ts +++ b/back/config/serverEnv.ts @@ -6,6 +6,14 @@ let pickedEnv: Record; function getPickedEnv() { if (pickedEnv) return pickedEnv; const picked = pick(process.env, ['QlBaseUrl', 'DeployEnv']); + if (picked.QlBaseUrl) { + if (!picked.QlBaseUrl.startsWith('/')) { + picked.QlBaseUrl = `/${picked.QlBaseUrl}` + } + if (!picked.QlBaseUrl.endsWith('/')) { + picked.QlBaseUrl = `${picked.QlBaseUrl}/` + } + } pickedEnv = picked as Record; return picked; } diff --git a/shell/share.sh b/shell/share.sh index 1afa18d2..96c4cafd 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -407,8 +407,18 @@ init_nginx() { local aliasStr="" local rootStr="" if [[ $ql_base_url != "/" ]]; then + if [[ $ql_base_url != /* ]]; then + ql_base_url="/$ql_base_url" + fi + if [[ $ql_base_url != */ ]]; then + ql_base_url="$ql_base_url/" + fi location_url="^~${ql_base_url%*/}" aliasStr="alias ${dir_static}/dist;" + if ! grep -q "" "${dir_static}/dist/index.html"; then + awk -v text="" '/ temp.html + mv temp.html "${dir_static}/dist/index.html" + fi else rootStr="root ${dir_static}/dist;" fi diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index ed47e961..a1c764d8 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -178,7 +178,7 @@ export default function () { useEffect(() => { if (!user || !user.username) return; const ws = WebSocketManager.getInstance( - `${window.location.origin}/api/ws?token=${localStorage.getItem( + `${window.location.origin}${window.__ENV__QlBaseUrl || '/'}api/ws?token=${localStorage.getItem( config.authKey, )}`, ); diff --git a/tsconfig.json b/tsconfig.json index 5b0609a9..fb34aa5c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { "target": "ESNext", - "module": "ES2015", - "moduleResolution": "Bundler", + "module": "commonjs", + "moduleResolution": "node", "importHelpers": true, "jsx": "react-jsx", "esModuleInterop": true, @@ -25,14 +25,7 @@ "include": ["src/**/*", ".umirc.ts", "typings.d.ts", "back/**/*"], "exclude": [ "node_modules", - "lib", - "es", "static", "data", - "typings", - "**/__test__", - "test", - "docs", - "tests" ] }