Files
WeKnora/frontend/docker-entrypoint.sh
wizardchen d6d177f3ab fix(i18n): harden DEFAULT_LOCALE runtime config after #2658
Whitelist locale tags in docker-entrypoint to prevent config.js injection,
extract resolveDefaultLocale with trim/validation, add unit tests, and sync
local dev config plus docs for the new deployment default language setting.
2026-08-12 10:53:23 +08:00

26 lines
819 B
Bash

#!/bin/sh
# 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
# 生成运行时配置文件,注入环境变量到前端
cat > /usr/share/nginx/html/config.js << EOF
window.__RUNTIME_CONFIG__ = {
MAX_FILE_SIZE_MB: ${MAX_FILE_SIZE_MB:-50},
DEFAULT_LOCALE: "${RUNTIME_DEFAULT_LOCALE}"
};
EOF
# 处理 nginx 配置
export MAX_FILE_SIZE=${MAX_FILE_SIZE_MB}M
export APP_HOST=${APP_HOST:-app}
export APP_PORT=${APP_PORT:-8080}
export APP_SCHEME=${APP_SCHEME:-http}
envsubst '${MAX_FILE_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;'