feat(env, config, i18n): 增强环境配置与多语言支持
更新 .env.example,提供更清晰的 API 配置说明与本地开发环境配置指引。 修改 next.config.ts:支持动态解析允许的开发环境来源(origins),提升配置灵活性。 重构 admin-language-switcher:优化语言切换同步机制,确保语言变更能够及时生效。 优化英文、尼泊尔语与中文语言包中的错误提示文案,进一步明确 API 配置要求。 精简 admin-http.ts:将 API Base URL 校验逻辑抽离至独立模块并统一导出,提升代码可维护性。
This commit is contained in:
19
src/lib/lottery-api-env.ts
Normal file
19
src/lib/lottery-api-env.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 管理端 API 连接方式:
|
||||
* - 默认:浏览器请求同源 `/api/*`,由 next.config `rewrites` 转发到 Laravel(需配置服务端 `API_BASE_URL`)。
|
||||
* - 可选:设置 `NEXT_PUBLIC_LOTTERY_API_BASE_URL` 直连后端(不经 Next 反代)。
|
||||
*/
|
||||
export function hasLotteryAdminApiBaseUrl(): boolean {
|
||||
const direct = process.env.NEXT_PUBLIC_LOTTERY_API_BASE_URL?.trim();
|
||||
if (direct !== undefined && direct !== "") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return process.env.NEXT_PUBLIC_LOTTERY_API_PROXY_DISABLED !== "true";
|
||||
}
|
||||
|
||||
/** 直连模式下的 Laravel API 根(含 `/api` 前缀由调用方 path 决定) */
|
||||
export function lotteryAdminApiDirectOrigin(): string | null {
|
||||
const direct = process.env.NEXT_PUBLIC_LOTTERY_API_BASE_URL?.trim();
|
||||
return direct !== undefined && direct !== "" ? direct.replace(/\/$/, "") : null;
|
||||
}
|
||||
Reference in New Issue
Block a user