Files
YMhut-box-C-/server/unified-management/README.md
T

149 lines
5.1 KiB
Markdown

# YMhut Unified Management
This service unifies the old `server/update` and `server/feedback-mailer` projects.
## Nginx Reverse Proxy
Production deployments should start from `deploy/nginx/unified-management.conf.example`. Set its domain, TLS settings, upstream port, and `/downloads/` alias for the current machine. Keep `client_max_body_size` at least 8 MiB above `YMHUT_RELEASE_UPLOAD_MAX_BYTES` for multipart overhead; the default service limit is 1 GiB.
The upload location disables request buffering so packages stream directly to Go and uses a 30-minute timeout. The download location lets Nginx send immutable package files without routing their bytes through the service. Run `nginx -t` before reloading a control-panel generated configuration.
## What It Provides
- Go backend with SQLite by default.
- Optional MySQL configuration with runtime status and failover hooks.
- Legacy routes for `update-info.json`, `tool-status.json`, `media-types.json`, `modules.json`, downloads, and feedback.
- New client discovery through `/api/client/bootstrap`.
- Admin login with default account `admin/admin`.
- Login captcha, HttpOnly session cookie, and CSRF checks.
- In-process media/data source service with scheduled health checks.
- Vue admin/portal source and Rust WASM helper source.
## Run
```powershell
cd server\unified-management
$env:GOPROXY="https://goproxy.io,https://mirrors.aliyun.com/goproxy,direct"
go mod download all
go mod verify
go run main.go
```
These commands only set the proxy for the current PowerShell process and do not modify the global Go configuration. Use `go mod tidy -diff` when reviewing dependency changes; normal startup must not rewrite `go.mod` or `go.sum`.
The startup preflight prints:
- the accepted entrypoint: `go run main.go`
- the listen address
- storage, SQLite, legacy JSON, downloads, and frontend dist status
Alternative command entrypoint:
```powershell
go run .\cmd\unified-management
```
Tests:
```powershell
.\scripts\test.ps1
```
The test and release scripts prefetch the complete module graph through a process-local proxy fallback and verify every module against `go.sum`/`GOSUMDB`. Override the proxy chain without changing global Go settings when needed:
```powershell
$env:YMHUT_GOPROXY="https://your-proxy.example,direct"
.\scripts\test.ps1 -Race
```
`-Race` requires a working C compiler in `PATH`; normal tests and release builds do not.
## Frontend Build Check
Startup preflight checks the selected admin asset source and both other built web apps. The admin build must include:
- `web/admin/dist/index.html`
- `web/admin/dist/asset-manifest.json`
- `web/admin/dist/admin-build.json`
- every entry, CSS file, asset, import, and dynamic import named by the manifest
- `web/portal/dist/index.html`
- `web/portal/dist/assets`
Release binaries built with `embed_web` default to the embedded admin build and never mix it with files from disk. Non-embedded development builds default to disk. Override this explicitly with `YMHUT_ADMIN_ASSET_MODE=embedded|disk`; an invalid or incomplete selected source is reported through `/api/admin/system/health` and is not replaced by files from the other source. Build the local dist files with:
```powershell
cd server\unified-management\web\admin
npm install
npm run build
npm run validate:build
cd ..\portal
npm install
npm run build
```
The Go server serves portal assets from `/assets/*` and admin assets from `/admin/assets/*`. Admin HTML is always `no-store`, hashed assets are immutable, and missing assets return 404 rather than the SPA shell. Production deployment replaces the single embedded service binary; do not copy `web/admin/dist` over a production binary.
## Release Binaries
Build frontend assets and produce merged backend binaries for Windows and Linux. The scripts run `npm run build` for both web apps and compile Go with `-tags embed_web`, so the resulting binaries include the admin and portal frontends:
```powershell
cd server\unified-management
.\scripts\build-release.ps1 -Version 0.1.0
```
Linux/macOS shell:
```bash
cd server/unified-management
VERSION=0.1.0 ./scripts/build-release.sh
```
Outputs are written to `dist-release/`:
- `ymhut-unified-management-windows-amd64.exe`
- `ymhut-unified-management-linux-amd64`
- `ymhut-unified-management-linux-arm64`
## Default Port
The default listen address is `:33550`.
Override it with either:
```powershell
$env:YMHUT_LISTEN=":33551"
```
or:
```powershell
$env:PORT="33551"
```
## Environment
- `YMHUT_LISTEN`: listen address, default `:33550`
- `YMHUT_BASE_URL`: public endpoint, default `https://update.ymhut.cn`
- `YMHUT_DB_PROVIDER`: `sqlite` or `mysql`
- `YMHUT_SQLITE_PATH`: SQLite path
- `YMHUT_MYSQL_DSN`: MySQL DSN
- `YMHUT_UPDATE_PUBLIC_DIR`: legacy update public directory
- `YMHUT_DOWNLOADS_DIR`: package download directory
- `YMHUT_SOURCE_CHECK_SECONDS`: source health check interval
## Frontend
- `web/admin`: Vue admin console source
- `web/portal`: Vue public portal source
- `web/wasm`: Rust WASM helpers
Rust WASM functions:
- `compareVersions`
- `normalizeReleaseManifest`
- `validateSourceCatalog`
- `scoreEndpointHealth`
- `mergeLegacyMediaTypes`