54 lines
2.3 KiB
Bash
54 lines
2.3 KiB
Bash
#!/bin/sh
|
||
set -e
|
||
|
||
# 从环境变量获取 APP_SHORT_NAME
|
||
APP_SHORT_NAME="${VITE_GLOB_APP_SHORT_NAME:-CQYTHEALTHADMIN}"
|
||
CONFIG_VAR="__PRODUCTION__${APP_SHORT_NAME}__CONF__"
|
||
|
||
# 1. 创建运行时配置文件
|
||
cat > /var/www/html/config.js << EOF
|
||
// 动态注入运行时配置
|
||
window['$CONFIG_VAR'] = {
|
||
"VITE_GLOB_APP_TITLE": "${VITE_GLOB_APP_TITLE:-健康管理后台}",
|
||
"VITE_GLOB_APP_TITLE_JD": "${VITE_GLOB_APP_TITLE_JD:-健康干预后台}",
|
||
"VITE_GLOB_APP_SHORT_NAME": "${VITE_GLOB_APP_SHORT_NAME:-CqytHealthAdmin}",
|
||
"VITE_GLOB_APP_CAS_BASE_URL": "${VITE_GLOB_APP_CAS_BASE_URL:-http://cas.default.com/cas}",
|
||
"VITE_GLOB_APP_OPEN_SSO": ${VITE_GLOB_APP_OPEN_SSO:-false},
|
||
"VITE_GLOB_APP_OPEN_QIANKUN": ${VITE_GLOB_APP_OPEN_QIANKUN:-true},
|
||
"VITE_GLOB_ONLINE_VIEW_URL": "${VITE_GLOB_ONLINE_VIEW_URL:-http://fileview.jeecg.com/onlinePreview}",
|
||
"VITE_GLOB_API_URL": "${VITE_GLOB_API_URL:-http://default-api.com}",
|
||
"VITE_GLOB_DOMAIN_URL": "${VITE_GLOB_DOMAIN_URL:-http://default-domain.com}",
|
||
"VITE_GLOB_ST_DOMAIN_URL": "${VITE_GLOB_ST_DOMAIN_URL:-http://default-domain.com}",
|
||
"VITE_GLOB_API_URL_PREFIX": "${VITE_GLOB_API_URL_PREFIX:-}",
|
||
"VITE_OUT_URL": "${VITE_OUT_URL:-}"
|
||
};
|
||
|
||
// 冻结对象(可选,模拟生产行为)
|
||
Object.freeze(window['$CONFIG_VAR']);
|
||
Object.defineProperty(window, '$CONFIG_VAR', {
|
||
configurable: false,
|
||
writable: false
|
||
});
|
||
EOF
|
||
|
||
# 2. 修改 index.html:
|
||
# - 在 </head> 前插入 <script src="/config.js">
|
||
# - 并注释或移除原始的 _app.config.js 加载
|
||
sed -i '/<head[ >]/a <script src="\/config.js" defer><\/script>' /var/www/html/index.html
|
||
|
||
# 3. 屏蔽原始 _app.config.js(通过注释 script 标签)
|
||
# 匹配 src="/_app.config.js" 开头,允许后面有 ?v=任意字符
|
||
sed -i 's|<script[^>]*src="/_app.config.js[^"]*"[^>]*></script>|<!-- 屏蔽构建时配置:<script src="/_app.config.js" /> -->|g' /var/www/html/index.html
|
||
|
||
## 在下载页面的静态文件中注入JS
|
||
# 1. 创建运行时配置文件
|
||
cat > /var/www/html/static/apps/configApp.js << EOF
|
||
// 动态注入运行时配置
|
||
window['downUrl'] = "${VITE_GLOB_API_URL:-http://default-api.com}";
|
||
EOF
|
||
|
||
sed -i '/<head[ >]/a <script src="configApp.js" defer><\/script>' /var/www/html/static/apps/experEnd.html
|
||
sed -i '/<head[ >]/a <script src="configApp.js" defer><\/script>' /var/www/html/static/apps/index.html
|
||
# 启动 Nginx
|
||
exec nginx -g "daemon off;"
|