forked from xiangwang25/whale-town-end-v2
docs: add backend deployment guide
This commit is contained in:
47
DEPLOYMENT.md
Normal file
47
DEPLOYMENT.md
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# WhaleTown V2 后端部署
|
||||||
|
|
||||||
|
## 1. 生产配置
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env.production.example .env
|
||||||
|
openssl rand -hex 32 # 分别用于 JWT_SECRET、ADMIN_TOKEN_SECRET 和 ZULIP_API_KEY_ENCRYPTION_KEY
|
||||||
|
```
|
||||||
|
|
||||||
|
必须填写 MySQL、Redis 和三个随机密钥。REST API 使用 `3000` 端口,原生 WebSocket 使用 `3001` 端口。不要把两个端口配成相同值。
|
||||||
|
|
||||||
|
## 2. 数据库
|
||||||
|
|
||||||
|
部署前先备份现有数据库。v2 不会自动修改表结构(`synchronize: false`)。根据目标库的现有结构审核并执行仓库内的增量 SQL:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mysql -u <user> -p <database> < src/core/db/player_assets/create-player-assets-tables.sql
|
||||||
|
mysql -u <user> -p <database> < src/core/db/user_wallets/create-user-wallets-tables.sql
|
||||||
|
mysql -u <user> -p <database> < src/business/notice/migrations/create-notices-table.sql
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. 构建与启动
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm install --frozen-lockfile
|
||||||
|
pnpm run build
|
||||||
|
VITE_API_BASE_URL=https://whaletownend.xinghangee.icu pnpm --filter whale-town-admin run build
|
||||||
|
pm2 start ecosystem.config.js
|
||||||
|
pm2 save
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4. 反向代理
|
||||||
|
|
||||||
|
`deploy/nginx/whaletownend-v2.conf.example` 将 REST 转发到 `3000`,将 `/game` WebSocket 转发到 `3001`。管理端可使用 `deploy/nginx/whaletown-admin-v2.conf.example` 作为独立静态站点。
|
||||||
|
|
||||||
|
启用 HTTPS 后验证:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl https://whaletownend.xinghangee.icu/
|
||||||
|
curl https://whaletownend.xinghangee.icu/api-docs
|
||||||
|
curl --http1.1 -i \
|
||||||
|
-H 'Connection: Upgrade' \
|
||||||
|
-H 'Upgrade: websocket' \
|
||||||
|
-H 'Sec-WebSocket-Version: 13' \
|
||||||
|
-H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' \
|
||||||
|
https://whaletownend.xinghangee.icu/game
|
||||||
|
```
|
||||||
@@ -29,7 +29,7 @@ pnpm run start:prod
|
|||||||
|
|
||||||
启动前至少需要在 `.env` 中设置随机的 `JWT_SECRET`、`ADMIN_TOKEN_SECRET` 和 `ZULIP_API_KEY_ENCRYPTION_KEY`。生产环境请从 `.env.production.example` 开始配置,不要直接使用示例值。
|
启动前至少需要在 `.env` 中设置随机的 `JWT_SECRET`、`ADMIN_TOKEN_SECRET` 和 `ZULIP_API_KEY_ENCRYPTION_KEY`。生产环境请从 `.env.production.example` 开始配置,不要直接使用示例值。
|
||||||
|
|
||||||
API 默认监听 `3000` 端口,Swagger 地址为 `/api-docs`。
|
REST API 默认监听 `3000` 端口,原生 WebSocket 默认监听 `3001` 端口并使用 `/game` 路径,Swagger 地址为 `/api-docs`。生产环境的反向代理需要分别转发这两个端口。
|
||||||
|
|
||||||
## 管理端
|
## 管理端
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user