refactor: 更新环境配置与 API 代理逻辑

- 修改 .env.example,优化玩家端配置说明,明确本地与线上环境的使用方式。
- 重构 API 代理逻辑,移除过时的开发代理文件,统一使用 Next.js 代理 API 请求。
- 更新 CSP 配置,简化连接来源说明,提升安全性。
- 调整 lottery-api-base.ts 中的注释,增强代码可读性。
This commit is contained in:
2026-05-29 15:55:19 +08:00
parent 2bc1d4748a
commit 4fc2b38a40
6 changed files with 68 additions and 20 deletions

53
ecosystem.config.cjs Normal file
View File

@@ -0,0 +1,53 @@
/**
* 玩家端lotteryfront宝塔 PM2 配置
*
* 部署步骤(在服务器项目目录执行):
* 1. 复制 .env.example 为 .env按线上域名填写见下方 env 说明)
* 2. npm ci && npm run build
* 3. 修改下方 cwd 为服务器上的实际路径
* 4. pm2 start ecosystem.config.cjs
* 5. pm2 save && pm2 startup # 开机自启(按 PM2 提示执行)
*
* 宝塔:网站 → Node 项目 → PM2 管理器 → 添加项目 → 选择本文件,或 SSH 执行 pm2 start。
* Nginx反代到 127.0.0.1:3800 即可;/api 由 Next 转发到 LOTTERY_API_UPSTREAM无需单独配。
*/
const path = require("path");
/** 改成服务器上的绝对路径,例如 /www/wwwroot/lottery.yourdomain.com */
const APP_CWD = path.resolve(__dirname);
module.exports = {
apps: [
{
name: "lotteryfront",
cwd: APP_CWD,
script: "node_modules/next/dist/bin/next",
args: "start -p 3800 -H 127.0.0.1",
interpreter: "node",
exec_mode: "fork",
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: "1G",
time: true,
merge_logs: true,
out_file: path.join(APP_CWD, "logs/pm2-out.log"),
error_file: path.join(APP_CWD, "logs/pm2-error.log"),
env: {
NODE_ENV: "production",
PORT: "3800",
// Laravel 根地址(无尾部 /);同机部署填 http://127.0.0.1:8000
LOTTERY_API_UPSTREAM: "http://127.0.0.1:8000",
// 构建时需存在;运行时可留空若已在 build 时写入
// NEXT_PUBLIC_MAIN_SITE_URL: "https://main.yourdomain.com",
},
// PM2 5.2+:可把变量放在 .env由 PM2 注入(需 npm run build 前也有一份供 Next 编译)
// env_file: path.join(APP_CWD, ".env"),
},
],
};