From b04b790a4da81d40dd2724137f3aee7822379368 Mon Sep 17 00:00:00 2001 From: Nikita Veselov Date: Tue, 25 Nov 2025 15:58:10 +0300 Subject: [PATCH] MSP-6791 add support public-path --- .env.example | 1 + Dockerfile | 11 +++++++---- cfg/80_isp-admin-ui.conf | 2 +- entrypoint.sh | 33 +++++++++++++++++++++++++++++---- index.html | 2 +- package-lock.json | 24 ++++++++++++------------ package.json | 4 ++-- vite.config.ts | 2 ++ 8 files changed, 55 insertions(+), 24 deletions(-) diff --git a/.env.example b/.env.example index 26a3034..d15b18c 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,3 @@ PROXY_URL= +PUBLIC_PATH= VITE_APP_TOKEN= diff --git a/Dockerfile b/Dockerfile index 14e8d16..c37ebca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ ARG NODE_VERSION=lts - +ARG PUBLIC_PATH=/ FROM node:${NODE_VERSION}-alpine as base WORKDIR /usr/src/app @@ -22,9 +22,12 @@ COPY . . RUN npm run build FROM nginx:alpine-slim as final + +ENV PUBLIC_PATH=$PUBLIC_PATH + RUN rm -f /etc/nginx/conf.d/default.conf COPY cfg/80_isp-admin-ui.conf /etc/nginx/conf.d/80_isp-admin-ui.conf -COPY --from=build /usr/src/app/build /opt/msp/isp-admin-ui +COPY --from=build /usr/src/app/build /opt/msp/isp-admin-ui${PUBLIC_PATH} -COPY entrypoint.sh /opt/msp/isp-admin-ui/entrypoint.sh -ENTRYPOINT ["/opt/msp/isp-admin-ui/entrypoint.sh"] +COPY entrypoint.sh /opt/msp/isp-admin-ui${PUBLIC_PATH}entrypoint.sh +ENTRYPOINT sh -c "/opt/msp/isp-admin-ui${PUBLIC_PATH}entrypoint.sh" diff --git a/cfg/80_isp-admin-ui.conf b/cfg/80_isp-admin-ui.conf index 0bbe130..8f1f3d9 100644 --- a/cfg/80_isp-admin-ui.conf +++ b/cfg/80_isp-admin-ui.conf @@ -7,7 +7,7 @@ server { add_header Cache-Control "no-cache, no-store, must-revalidate"; add_header Pragma "no-cache"; # Для совместимости с HTTP/1.0 expires off; - try_files $uri /index.html; + try_files $uri __PUBLIC_PATH__index.html; } location /api { diff --git a/entrypoint.sh b/entrypoint.sh index 9076b48..e36fee7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,16 +1,41 @@ #!/bin/sh +set -e -CONFIG_PATH="/opt/msp/isp-admin-ui/config.js" +PUBLIC_PATH="${PUBLIC_PATH:-/}" -cat < $CONFIG_PATH -// DON'T TOUCH -// THIS FILE FOR PRODUCTION BUILD +PUBLIC_PATH="$(echo "$PUBLIC_PATH" | sed -E 's|^/*|/|; s|/*$|/|')" +echo "Using normalized PUBLIC_PATH: '$PUBLIC_PATH'" + +# Генерация конфигурации приложения +CONFIG_DIR="/opt/msp/isp-admin-ui${PUBLIC_PATH}" +CONFIG_PATH="${CONFIG_DIR}config.js" + +mkdir -p "$CONFIG_DIR" + +cat < "$CONFIG_PATH" window.config = { ENABLE_PASSWORD_LOGIN: ${ENABLE_PASSWORD_LOGIN:-true}, APP_TOKEN: '${APP_TOKEN:-"default_token"}', }; EOF +echo "Generated config at: $CONFIG_PATH" +# Подготовка nginx-конфига: заменяем __PUBLIC_PATH__ на реальное значение +NGINX_SRC="/etc/nginx/conf.d/80_isp-admin-ui.conf" +TMP_FILE="${NGINX_SRC}.tmp" + +echo "Substituting __PUBLIC_PATH__ with: '${PUBLIC_PATH}'" +sed "s|__PUBLIC_PATH__|${PUBLIC_PATH}|g" "$NGINX_SRC" > "$TMP_FILE" + +# Проверка результата +echo "=== Generated nginx config ===" +cat "$TMP_FILE" +echo "=== End nginx config ===" + +# Заменяем оригинальный конфиг +mv "$TMP_FILE" "$NGINX_SRC" + +echo "Starting nginx..." exec nginx -g "daemon off;" diff --git a/index.html b/index.html index 85cc9d6..0e3f7ec 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ - + Панель администратора diff --git a/package-lock.json b/package-lock.json index ce4996f..6db2ac0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,8 +12,8 @@ "@reduxjs/toolkit": "^2.2.3", "axios": "^1.7.7", "dayjs": "^1.11.10", - "isp-admin-ui-kit": "^1.4.1", - "isp-ui-kit": "^0.22.1", + "isp-admin-ui-kit": "^1.5.2", + "isp-ui-kit": "^0.23.0", "monaco-editor": "^0.52.0", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -9709,9 +9709,9 @@ } }, "node_modules/isp-admin-ui-kit": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/isp-admin-ui-kit/-/isp-admin-ui-kit-1.4.1.tgz", - "integrity": "sha512-H3EIFDRUzlLsJVI01S6KxvN73hSkuV6FtK3C5djKbWoPmd+LK8rlodAmY2TjBfHoG9upJbwyJMHKdWRpiXYJLQ==", + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/isp-admin-ui-kit/-/isp-admin-ui-kit-1.5.2.tgz", + "integrity": "sha512-lwg7q4UD0fP+YE8bCSIz/KZKg/+WjBrRsnfQeuNydcznpZjuUuJm9GaE50Hu3WVd2HqBeD4mMlHeN55onBQP0g==", "dependencies": { "@apidevtools/json-schema-ref-parser": "^9.0.6", "@rjsf/antd": "^5.21.2", @@ -9726,7 +9726,7 @@ "simplebar-react": "^3.2.4" }, "optionalDependencies": { - "@rollup/rollup-linux-x64-gnu": "^4.52.5" + "@rollup/rollup-linux-x64-gnu": "^4.53.3" }, "peerDependencies": { "@monaco-editor/react": "^4.6.0", @@ -9744,9 +9744,9 @@ } }, "node_modules/isp-admin-ui-kit/node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.52.5", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.52.5.tgz", - "integrity": "sha512-hXGLYpdhiNElzN770+H2nlx+jRog8TyynpTVzdlc6bndktjKWyZyiCsuDAlpd+j+W+WNqfcyAWz9HxxIGfZm1Q==", + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.53.3.tgz", + "integrity": "sha512-3EhFi1FU6YL8HTUJZ51imGJWEX//ajQPfqWLI3BQq4TlvHy4X0MOr5q3D2Zof/ka0d5FNdPwZXm3Yyib/UEd+w==", "cpu": [ "x64" ], @@ -9757,9 +9757,9 @@ ] }, "node_modules/isp-ui-kit": { - "version": "0.22.1", - "resolved": "https://registry.npmjs.org/isp-ui-kit/-/isp-ui-kit-0.22.1.tgz", - "integrity": "sha512-8eJy4g7rW2MAGUpQxiUvuuYyaRXZ3jcrSg0UZknfMY4cGt6Sae4C1816H/okMojs2spI8RkDV5w6YqBTfC2J0w==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/isp-ui-kit/-/isp-ui-kit-0.23.0.tgz", + "integrity": "sha512-VH7VlGEwFO59xlZBwAJLlNZZp1Gi4k9QiSjVspDXosMK0c48WHOi6nYeKQxYtR3owGFm4lPsDNH85C67457CiA==", "license": "MIT", "dependencies": { "dayjs": "^1.11.13", diff --git a/package.json b/package.json index 8956cc7..13e61f9 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,8 @@ "@reduxjs/toolkit": "^2.2.3", "axios": "^1.7.7", "dayjs": "^1.11.10", - "isp-admin-ui-kit": "^1.4.1", - "isp-ui-kit": "^0.22.1", + "isp-admin-ui-kit": "^1.5.2", + "isp-ui-kit": "^0.23.0", "monaco-editor": "^0.52.0", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/vite.config.ts b/vite.config.ts index 715d7cd..1032b2c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -8,7 +8,9 @@ import tsconfigPaths from 'vite-tsconfig-paths' // https://vitejs.dev/config/ export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), '') + return { + base: env.PUBLIC_PATH || '/', optimizeDeps: { exclude: [] }, define: { __APP_ENV__: env.APP_ENV,