Files
SupplierSystem/server/scripts/fix-h5-nginx-behind-clb.mjs
T
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库:jxc/ai-fresh-delivery
来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d
快照树:  09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件)

按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据
(生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、
deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

77 lines
2.4 KiB
JavaScript

/**
* On H5 nodes: avoid unconditional HTTP→HTTPS redirect when behind CLB
* (CLB terminates TLS and forwards HTTP). Prefer X-Forwarded-Proto.
*/
import { loadTencentCredentials, runShellCommand } from './tencent-lib.mjs';
const SCRIPT = `#!/bin/bash
set -euo pipefail
echo "HOST=$(hostname)"
CONF=""
for f in /etc/nginx/sites-enabled/* /etc/nginx/conf.d/*.conf; do
[ -f "$f" ] || continue
if grep -qE 'server_name|listen 80' "$f" 2>/dev/null; then CONF="$f"; break; fi
done
echo "CONF=$CONF"
if [ -z "$CONF" ]; then echo 'no nginx site conf'; exit 0; fi
cp -a "$CONF" "$CONF.bak.$(date +%s)"
# Replace bare 'return 301 https://...' with proto-aware redirect
python3 - <<'PY'
import pathlib, re, sys
paths=[]
for p in pathlib.Path('/etc/nginx/sites-enabled').glob('*'):
paths.append(p)
for p in pathlib.Path('/etc/nginx/conf.d').glob('*.conf'):
paths.append(p)
changed=False
for path in paths:
text=path.read_text(encoding='utf-8', errors='ignore')
orig=text
# common patterns
text=re.sub(
r'(?m)^(\\s*)return\\s+301\\s+https://\\$host\\$request_uri;\\s*$',
r'\\1if ($http_x_forwarded_proto != "https") { return 301 https://$host$request_uri; }',
text,
)
text=re.sub(
r'(?m)^(\\s*)return\\s+301\\s+https://www\\.xdjchuanhui\\.com\\$request_uri;\\s*$',
r'\\1if ($http_x_forwarded_proto != "https") { return 301 https://www.xdjchuanhui.com$request_uri; }',
text,
)
if text!=orig:
path.write_text(text, encoding='utf-8')
print('patched', path)
changed=True
if not changed:
print('no unconditional 301 https redirect found (or already patched)')
PY
nginx -t
systemctl reload nginx
curl -sS -o /dev/null -w 'local80=%{http_code}\\n' http://127.0.0.1/ || true
curl -sS -o /dev/null -w 'as_https=%{http_code}\\n' -H 'X-Forwarded-Proto: https' -H 'Host: www.xdjchuanhui.com' http://127.0.0.1/ || true
`;
async function main() {
const cred = loadTencentCredentials();
for (const id of ['ins-9zdly5wm', 'ins-hvq9s3gi']) {
console.log('===', id);
try {
const out = await runShellCommand(
{ secretId: cred.secretId, secretKey: cred.secretKey },
'ap-nanjing',
[id],
SCRIPT,
120
);
console.log(out);
} catch (e) {
console.error(id, e.message);
}
}
}
main().catch((e) => {
console.error(e);
process.exit(1);
});