Files
youlegames/codes/agent/game-docker/docker/api/docker-entrypoint.sh
2026-04-13 17:06:02 +08:00

72 lines
2.9 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -e
# ============================================
# API 服务启动入口脚本
# 在 Apache 启动前替换静态 JS 文件中的硬编码域名
# ============================================
echo "[entrypoint] Replacing hardcoded domains in JS files..."
# 默认值(与 .env.example 对应)
# 从 ROOT_DOMAIN 推导子域名docker-compose.yml 通常已注入,这里仅作容器外单跑的兜底)
_ROOT="${ROOT_DOMAIN:-daoqijuyou77.cn}"
SITE_API_URL="${SITE_API_URL:-https://api.${_ROOT}}"
SITE_PAY_NOTIFY_URL="${SITE_PAY_NOTIFY_URL:-https://api.${_ROOT}}"
SITE_API2_URL="${SITE_API2_URL:-https://api2.tscce.cn}"
QQ_CALLBACK_URL="${QQ_CALLBACK_URL:-http://syhd.daoqijuyou77.cn}"
# 替换 api/source/pay/js/common.js 和 api/source/login/js/common.js 中的 g_RequestAddress
for f in /var/www/html/source/pay/js/common.js /var/www/html/source/login/js/common.js; do
if [ -f "$f" ]; then
sed -i "s|var g_RequestAddress = 'https://api2.tscce.cn'|var g_RequestAddress = '${SITE_API2_URL}'|g" "$f"
echo "[entrypoint] Updated: $f"
fi
done
# 替换 QQ 登录配置中的回调地址
QQ_INC="/var/www/html/loginLib/qq/API/comm/inc.php"
if [ -f "$QQ_INC" ]; then
sed -i "s|__QQ_CALLBACK_URL__|${QQ_CALLBACK_URL}|g" "$QQ_INC"
echo "[entrypoint] Updated: $QQ_INC"
fi
# 替换 sample 目录中的硬编码域名
for f in /var/www/html/sample/onlinepay/js/common.js; do
if [ -f "$f" ]; then
sed -i "s|var g_RequestAddress = 'https://api.tscce.cn'|var g_RequestAddress = '${SITE_API_URL}'|g" "$f"
echo "[entrypoint] Updated: $f"
fi
done
for f in /var/www/html/sample/offlinepay/js/common.js; do
if [ -f "$f" ]; then
sed -i "s|var g_RequestAddress = 'https://api.daoqijuyou77.cn'|var g_RequestAddress = '${SITE_API_URL}'|g" "$f"
echo "[entrypoint] Updated: $f"
fi
done
for f in /var/www/html/sample/transfer/js/common.js /var/www/html/sample/refund/js/common.js; do
if [ -f "$f" ]; then
sed -i "s|var g_RequestAddress = 'https://api2.tscce.cn'|var g_RequestAddress = '${SITE_API2_URL}'|g" "$f"
sed -i "s|var g_RequestAddress = 'https://api2.daoqijuyou77.cn'|var g_RequestAddress = '${SITE_API2_URL}'|g" "$f"
echo "[entrypoint] Updated: $f"
fi
done
# 替换 sample PHP 文件中的硬编码域名
SAMPLE_DIR="/var/www/html/sample"
if [ -d "$SAMPLE_DIR" ]; then
# onlinepay/test.php 和 onlinepay/index.php
find "$SAMPLE_DIR" -name "*.php" -exec sed -i \
-e "s|https://api.tscce.cn|${SITE_API_URL}|g" \
-e "s|https://api2.tscce.cn|${SITE_API2_URL}|g" \
-e "s|https://api2.daoqijuyou77.cn|${SITE_API2_URL}|g" \
-e "s|https://api.daoqijuyou77.cn|${SITE_API_URL}|g" \
{} +
echo "[entrypoint] Updated: sample/ PHP files"
fi
echo "[entrypoint] Domain replacement complete. Starting Apache..."
# 启动 Apache前台运行
exec apache2-foreground