Files
FE-DEVICE-SGW/README.md
2025-11-21 14:27:00 +07:00

39 lines
2.1 KiB
Markdown

# README
`@umijs/max` 模板项目,更多功能参考 [Umi Max 简介](https://umijs.org/docs/max/introduce)
## Language Switching
- Lang toggle components (`src/components/switch/LangSwitches.tsx`, `src/components/LanguageSwitcher/index.tsx`) call Umi `setLocale(newLocale, false)` so content re-renders instantly without refreshing the page.
- Both components listen for the browser `languagechange` event to keep their UI state in sync when another part of the app switches languages.
- Strings are translated via `useTranslation`/`useIntl`; ensure new labels have entries in `src/locales/en-US.ts` and `src/locales/vi-VN.ts`.
## Proxy & Request Profiles
- Project uses two sets of configs under `config/`:
- `proxy.ts` + `Request.ts` for local development API targets.
- `proxy_prod.ts` + `request_prod.ts` for production-like targets.
- The runtime selects configs automatically:
- `pnpm run dev` / any dev server run ⇒ `NODE_ENV=development` ⇒ uses dev proxy/request.
- `pnpm run build` (and other production builds) ⇒ `NODE_ENV=production` ⇒ uses prod proxy/request.
- Override the environment by exporting `REACT_APP_ENV` before running commands (values: `dev`, `test`, `prod`). Example:
```bash
# Use test upstreams in a dev session
REACT_APP_ENV=test pnpm run dev
# Build with testing endpoints
NODE_ENV=production REACT_APP_ENV=test pnpm run build
```
- `config/proxy_prod.ts` resolves targets dynamically based on the current hostname; adjust rules there if deployment hosts change.
- Request pipelines differ per mode:
- `config/request_dev.ts` keeps relative URLs so calls pass through the dev proxy setup (use when mocking/pointing to LAN services).
- `config/request_prod.ts` builds absolute URLs from `ApiConfigService` so static builds call the correct host without relying on the proxy.
## Verifying Builds
- After switching language, confirm UI updates immediately and check console for `languagechange` events.
- For proxy changes, inspect network requests in devtools to ensure they hit the expected environment.
- Run `pnpm run build && pnpm serve` (or your hosting preview) to validate prod settings before deploying.