48 lines
1.6 KiB
Markdown
48 lines
1.6 KiB
Markdown
# 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
|
||
```
|