#!/bin/bash set -e # ============================================ # API 服务启动入口脚本 # 在 Apache 启动前替换静态 JS 文件中的硬编码域名 # ============================================ echo "[entrypoint] Replacing hardcoded domains in JS files..." # 默认值(与 .env.example 对应) 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 目录中的硬编码域名 SITE_API_URL="${SITE_API_URL:-https://api.tscce.cn}" SITE_PAY_NOTIFY_URL="${SITE_PAY_NOTIFY_URL:-http://api.daoqijuyou77.cn}" 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