#!/bin/sh set -eu # Only emit whitelisted locale tags to avoid config.js injection from env values. RUNTIME_DEFAULT_LOCALE="" case "${DEFAULT_LOCALE:-}" in zh-CN|en-US|ru-RU|ko-KR) RUNTIME_DEFAULT_LOCALE="${DEFAULT_LOCALE}" ;; esac # 生成运行时配置文件,注入环境变量到前端 FILE_MB=${MAX_FILE_SIZE_MB:-50} # Keep the browser and nginx in lockstep with the Go application ceiling. # Values above 20 GiB are rejected by the backend and must not produce a # misleadingly larger client-side limit or an oversized nginx request body. case "$FILE_MB" in ''|*[!0-9]*) FILE_MB=50 ;; esac if [ "$FILE_MB" -gt 20480 ]; then FILE_MB=20480 fi if [ "$FILE_MB" -le 0 ]; then FILE_MB=50 fi SKILL_MB=${MAX_SKILL_BUNDLE_SIZE_MB:-256} case "$SKILL_MB" in ''|*[!0-9]*) SKILL_MB=256 ;; esac if [ "$SKILL_MB" -lt "$FILE_MB" ] 2>/dev/null; then SKILL_MB=$FILE_MB fi if [ "$SKILL_MB" -gt 512 ] 2>/dev/null; then SKILL_MB=512 fi cat > /usr/share/nginx/html/config.js << EOF window.__RUNTIME_CONFIG__ = { MAX_FILE_SIZE_MB: ${FILE_MB}, MAX_SKILL_BUNDLE_SIZE_MB: ${SKILL_MB}, DEFAULT_LOCALE: "${RUNTIME_DEFAULT_LOCALE}" }; EOF # Rebuild from immutable templates on every start, including restarts with a # changed locale. Inlining removes a blocking request before the app can boot. for PAGE in index.html embed.html; do awk ' NR == FNR { config = config $0 "\n"; next } /" next } { print } END { if (replaced != 1) exit 1 } ' /usr/share/nginx/html/config.js \ "/usr/share/nginx/runtime-templates/$PAGE" > "/usr/share/nginx/html/$PAGE.next" mv "/usr/share/nginx/html/$PAGE.next" "/usr/share/nginx/html/$PAGE" done # 处理 nginx 配置。 # 两个上限分开注入:全站保持知识库的 MAX_FILE_SIZE,只有技能 zip 上传的两条 # 集合路由放宽到 MAX_SKILL_BUNDLE_SIZE(不含 /install、PATCH 等子路径)。 # 合成一个全站上限会让每个上传端点都能收到技能包那么大的 body。 export MAX_FILE_SIZE=${FILE_MB}M export MAX_SKILL_BUNDLE_SIZE=${SKILL_MB}M export APP_HOST=${APP_HOST:-app} export APP_PORT=${APP_PORT:-8080} export APP_SCHEME=${APP_SCHEME:-http} envsubst '${MAX_FILE_SIZE} ${MAX_SKILL_BUNDLE_SIZE} ${APP_HOST} ${APP_PORT} ${APP_SCHEME}' \ < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf # 启动 nginx exec nginx -g 'daemon off;'