oms/tools/config/deploy.config.example.cjs
liufumingren 122eb9ccc9 feat(frontend): 生产改为同源 /api,前端挂到后端域名的根目录
- frontend/.env.production: VITE_API_BASE_URL 由 https://api.oms.gztbyc.com/api 改为 /api
- tools/DEPLOY.md: 新增单站点 Nginx 配置(root=current、/api/ include upstream、SPA try_files 回退),
  域名/CORS 章节改为同源说明
- tools/config/deploy.config.example.cjs: Nginx 前置说明同步为单站点

同源后不再需要 CORS,后端切换 v1/v2 端口时前端产物无需重新构建。

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-30 23:13:44 +08:00

117 lines
4.9 KiB
JavaScript
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.

'use strict';
/**
* OMS 发布配置模板(此文件提交 git,供复制使用)
*
* 使用方式:
* cd tools && npm run init # 生成 deploy.config.local.cjs
* 然后填写 SSH / 目录等真实信息
* deploy.config.local.cjs 已被 .gitignore 排除,**不要提交**(内含服务器地址与私钥路径)。
*
* 发布模型(一次发布同时更新前后端):
* 后端:<deployRoot>/{v1,v2} 双实例蓝绿 + current.md + nginx-upstream.conf
* 前端:<basePath>/releases/<版本>/ 目录 + current 软链接原子切换
*
* <deployRoot>/shared-config/ 服务端共享配置(不入库):可放 config.*.js 与 .env;
* 每次发布复制到版本目录,覆盖包内同名文件
* <deployRoot>/.deploy/ 发布工作目录:incoming 上传包、backups 备份、state 版本记录
*
* Nginx 前置(仅首次,单站点 oms.gztbyc.com):
* 站点根目录指向 <basePath>/current(前端静态),`location /` 用 try_files 回退 index.html;
* `location /api/` 里 `include /www/wwwroot/api.oms.gztbyc.com/nginx-upstream.conf;`
* (该文件内容为 `proxy_pass http://127.0.0.1:<端口>;`,由发布脚本切换 v1/v2 端口)。
* 完整示例见 tools/DEPLOY.md。
*/
module.exports = {
production: {
// ==================== SSH ====================
host: '__FILL_SSH_HOST__',
port: 22,
username: '__FILL_SSH_USERNAME__',
// 私钥:绝对路径、~/ 开头,或相对仓库根目录的路径
privateKeyPath: '__FILL_PRIVATE_KEY_PATH__',
sshOptions: [ 'StrictHostKeyChecking=accept-new' ],
// ==================== 发布约束(受限于 git)====================
// 工作区有未提交改动时禁止发布(可用 npm run deploy -- --allow-dirty 临时放行)
allowDirtyGit: false,
// 远端保留的版本记录条数 / 备份包个数
keepVersions: 30,
keepBackups: 5,
// ==================== 后端(Egg 双实例蓝绿)====================
backend: {
deployRoot: '/www/wwwroot/api.oms.gztbyc.com',
// 双实例端口;nginx-upstream.conf 指向当前活跃版本的端口
ports: { v1: 6090, v2: 6091 },
// 新实例启动后轮询 http://127.0.0.1:<端口><healthCheckPath>
healthCheckPath: '/',
healthCheckAttempts: 10,
healthCheckInterval: 2,
// 清理旧代码时保留的目录(位于版本目录内)
// 注意:.env 不保留,每次发布都从 shared-config 重新覆盖
sharedDirs: [ 'logs', 'run', 'node_modules' ],
// 发布包内容(相对 backend 根目录,`**` 表示该目录下全部内容)
deployIncludePaths: [
'.sequelizerc',
'app.js',
'app/**',
'config/**',
'database/**',
'package.json',
'package-lock.json',
],
deployExcludePaths: [
'.env',
'.env.*',
'uploads/**',
'logs/**',
'run/**',
'temp/**',
'test/**',
'swagger.json',
],
// 远端安装 / 启动命令;实例端口由发布脚本强制注入 EGG_PORT,无需写进 .env
installCommand: 'npm install --production',
startCommand: 'npm start',
// 启动前是否执行数据库迁移(npm run migration:up,需要 installCommand 安装 devDependencies)
runMigrations: false,
startTitlePrefix: 'oms',
// ===== 服务端共享配置(后端的配置共享出来)=====
// 不写该字段则默认 <deployRoot>/shared-config;设为 '' 表示不启用共享配置
// 共享目录内可放 config.*.js 与 envFile,发布时复制到版本目录并覆盖包内同名文件
envFile: '.env',
// 本机权威副本(相对仓库根目录,已 gitignore);存在时发布前上传,覆盖服务端共享 env
envFileLocalPath: 'tools/config/env.production.local',
uploadEnvFile: true,
// ===== Nginx =====
// 不写 nginxUpstreamFile 则默认 <deployRoot>/nginx-upstream.conf;设为 '' 表示不管理 upstream
// 切换 upstream 后执行的重载命令;设为 '' 则只写文件不重载
nginxReloadCommand: 'nginx -t && nginx -s reload',
},
// ==================== 前端(releases + current 软链)====================
frontend: {
// false 表示本次发布不动前端
enabled: true,
// 站点根目录,releases/ 与 current 都在其下
basePath: '/www/wwwroot/oms.gztbyc.com',
// 本机构建产物的目录(相对仓库根目录)
distDir: 'frontend/dist',
// 发布前本地构建命令(在 frontend/ 下执行)
buildCommand: 'npm run build',
// 服务器保留的最近版本数
keepReleases: 5,
// 发版后健康检查用的域名(本机 curl 带 Host 头访问 https://127.0.0.1/,仅提示)
siteHost: 'oms.gztbyc.com',
},
},
};