This repository contains a Turbo monorepo for online Chinese chess:
apps/web: Vue 3 + Vite frontendapps/server: Express + Socket.IO backendpackages/game-core: shared game and protocol logic
pnpm installpnpm dev
By default:
- Web runs on the Vite dev server
- Server runs on
http://127.0.0.1:3001 - Web connects to the backend through
apps/web/.env.development
Useful commands:
pnpm devpnpm buildpnpm lintpnpm typecheckpnpm test
Production deployment now supports a single container:
- frontend assets are built into
apps/web/dist - the backend serves static files, HTTP endpoints, and Socket.IO from one process
- the frontend uses same-origin Socket.IO by default in production, so
VITE_WSis only needed for local development
Build the image:
docker build -t chess-app .Run the container:
docker run --rm -p 3001:3001 chess-appRun on a custom port:
docker run --rm -e PORT=8080 -p 8080:8080 chess-appAfter startup:
- app:
http://127.0.0.1:3001 - health check:
http://127.0.0.1:3001/healthz
基于 Turborepo 的联机象棋仓库,包含:
apps/web:Vue 3 + Vite 前端apps/server:TypeScript + Socket.IO 服务端
pnpm installpnpm dev
默认情况下:
- Web 启动在 Vite 默认端口
- Server 启动在
http://127.0.0.1:3001 - Web 通过
apps/web/.env.development中的VITE_WS连接服务端
pnpm dev:并行启动前后端pnpm build:构建全部应用pnpm lint:运行全部 lintpnpm typecheck:运行全部类型检查pnpm --filter @chess/web dev:只启动前端pnpm --filter @chess/server dev:只启动服务端
仓库根目录现在包含:
Dockerfile:单容器构建前后端docker-compose.yml:编排app + nginxdeploy/nginx/default.conf:支持 Socket.IO 的 Nginx 反向代理.env.deploy.example:部署环境变量示例
推荐部署流程:
- 本地或 CI 构建镜像
docker build -t your-registry/chess-app:latest .- 推送到镜像仓库
docker push your-registry/chess-app:latest- 在服务器上准备 compose 环境变量
cp .env.deploy.example .env把 .env 里的 APP_IMAGE 改成你的镜像地址,例如:
APP_IMAGE=your-registry/chess-app:latest
HTTP_PORT=80- 启动服务
docker compose pull
docker compose up -d- 检查状态
docker compose ps
docker compose logs -f app
curl http://127.0.0.1/healthz默认情况下:
- 外部访问入口是
nginx容器的80端口 - 应用容器只在 compose 内部网络监听
3001 - WebSocket 与普通 HTTP 请求都通过 Nginx 转发
如果你的服务器已经有宿主机 Nginx:
- 可以只运行
app容器,把它映射到127.0.0.1:3001:3001 - 然后参考
deploy/nginx/default.conf,把上游地址从app:3001改成127.0.0.1:3001 - HTTPS 证书也更适合放在宿主机 Nginx 或 Caddy 上统一处理
这条部署路径适合:
- 服务器已经装了宿主机 Nginx
- 想把 HTTPS、证书续期、多个站点统一交给宿主机处理
- Docker 里只跑应用容器,不再额外跑一个 Nginx 容器
相关文件:
docker-compose.host-nginx.yml:只启动app容器,并绑定到127.0.0.1:3001.env.host.example:宿主机 Nginx 模式的环境变量示例deploy/scripts/deploy-host-nginx.sh:Ubuntu 部署应用容器脚本deploy/nginx/chess.host-http.conf.example:Ubuntu 原生 Nginx 的 HTTP 反代模板deploy/nginx/chess.host-https.conf.example:Ubuntu 原生 Nginx 的 HTTPS 反代模板deploy/nginx/chess.baota-snippet.conf.example:宝塔站点里可直接粘贴的反代片段
cp .env.host.example .env.host把 .env.host 改成你的镜像地址,例如:
APP_IMAGE=your-registry/chess-app:latest
APP_PORT=3001如果你打算直接在服务器本机执行构建,也可以先运行:
docker build -t chess-app:latest .然后保留:
APP_IMAGE=chess-app:latest然后执行:
sh deploy/scripts/deploy-host-nginx.sh执行成功后,应用只会监听宿主机本地:
curl http://127.0.0.1:3001/healthz先安装 Nginx:
sudo apt update
sudo apt install -y nginx如果你还没有证书,先用 HTTP 模板把站点跑起来:
sudo cp deploy/nginx/chess.host-http.conf.example /etc/nginx/sites-available/chess.conf
sudo ln -sf /etc/nginx/sites-available/chess.conf /etc/nginx/sites-enabled/chess.conf然后把配置里的:
example.comwww.example.com127.0.0.1:3001(如果你改了APP_PORT)
替换成你的实际值,再执行:
sudo nginx -t
sudo systemctl reload nginx证书准备好以后,把站点配置替换为 deploy/nginx/chess.host-https.conf.example 对应内容,再次校验并重载:
sudo nginx -t
sudo systemctl reload nginx如果你使用 Certbot,常见安装方式是:
sudo apt install -y certbot python3-certbot-nginx宝塔更推荐:
- 在面板里先创建站点并绑定域名
- 在面板里申请 SSL 证书
- 打开站点配置,把
deploy/nginx/chess.baota-snippet.conf.example中的内容粘进去 - 确认反代目标是
http://127.0.0.1:3001 - 保存并重载 Nginx
curl -I http://127.0.0.1:3001/healthz
curl -I https://your-domain/healthz
docker compose --env-file .env.host -f docker-compose.host-nginx.yml ps
docker compose --env-file .env.host -f docker-compose.host-nginx.yml logs -f app- 绘制棋盘棋子
- 棋子逻辑
- 联机
- 翻转文字
- 相机设置
- 更多的材质
- 环境
- 重连
- 换人
- 将军提示
- SVGLoader
- 优化数组比较方法