From 27727f6371fc10951e41fcfa4e4216a4fc6e00a9 Mon Sep 17 00:00:00 2001 From: kang Date: Fri, 29 May 2026 09:17:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(env,=20config,=20i18n):=20=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=E7=8E=AF=E5=A2=83=E9=85=8D=E7=BD=AE=E4=B8=8E=E5=A4=9A?= =?UTF-8?q?=E8=AF=AD=E8=A8=80=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新 .env.example,提供更清晰的 API 配置说明与本地开发环境配置指引。 修改 next.config.ts:支持动态解析允许的开发环境来源(origins),提升配置灵活性。 重构 admin-language-switcher:优化语言切换同步机制,确保语言变更能够及时生效。 优化英文、尼泊尔语与中文语言包中的错误提示文案,进一步明确 API 配置要求。 精简 admin-http.ts:将 API Base URL 校验逻辑抽离至独立模块并统一导出,提升代码可维护性。 --- .env.example | 23 +++++++++++++++++++ next.config.ts | 5 +++- src/app/layout.tsx | 9 +++----- .../admin/admin-language-switcher.tsx | 18 ++++++++++----- src/i18n/locales/en/auth.json | 2 +- src/i18n/locales/ne/auth.json | 2 +- src/i18n/locales/zh/auth.json | 2 +- src/lib/admin-http.ts | 4 +--- src/lib/lottery-api-env.ts | 19 +++++++++++++++ src/lib/next-dev-origins.ts | 11 +++++++++ 10 files changed, 76 insertions(+), 19 deletions(-) create mode 100644 src/lib/lottery-api-env.ts create mode 100644 src/lib/next-dev-origins.ts diff --git a/.env.example b/.env.example index 23af0ee..2d6d262 100644 --- a/.env.example +++ b/.env.example @@ -1,9 +1,32 @@ # ============================================================================= # 管理端本地配置示例:复制为 .env.local 后按需修改 # ============================================================================= +# 三端联调速查(lotterLaravel + lotteryadmin + lotteryfront): +# - Laravel API:php artisan serve → 默认 http://127.0.0.1:8000 +# - 管理端:npm run dev → http://localhost:3801(浏览器请求 /api → 反代到 API_BASE_URL) +# - 玩家端:npm run dev → http://localhost:3800 +# - Laravel .env:CORS_ALLOWED_ORIGINS、SANCTUM_STATEFUL_DOMAINS 需包含上述前端 origin +# - Reverb:Laravel REVERB_* 与玩家端 NEXT_PUBLIC_REVERB_* 一致(管理端一般不需 Echo) + +# ----------------------------------------------------------------------------- +# Laravel API(Next rewrites:/api/* → ${API_BASE_URL}/api/*) +# ----------------------------------------------------------------------------- # 手动切换环境:保留一个生效,另一个注释掉 # 测试 API_BASE_URL=http://127.0.0.1:8000 # 线上 # API_BASE_URL=https://api.your-production-domain.com + +# ----------------------------------------------------------------------------- +# 可选:直连 Laravel(不经 Next 反代);一般本地开发用 API_BASE_URL 即可 +# ----------------------------------------------------------------------------- +# NEXT_PUBLIC_LOTTERY_API_BASE_URL=http://127.0.0.1:8000 +# 显式关闭「已配置 API」检测(极少用) +# NEXT_PUBLIC_LOTTERY_API_PROXY_DISABLED=true + +# ----------------------------------------------------------------------------- +# Next 开发:局域网用 IP 访问时,允许该 host(逗号分隔,无协议) +# 示例:手机访问 http://192.168.0.101:3801 时设置 +# ----------------------------------------------------------------------------- +# ALLOWED_DEV_ORIGINS=192.168.0.101 diff --git a/next.config.ts b/next.config.ts index 592a699..065aff7 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,10 +1,13 @@ import type { NextConfig } from "next"; +import { parseAllowedDevOrigins } from "./src/lib/next-dev-origins"; + const apiBaseUrl = process.env.API_BASE_URL?.trim() || "http://127.0.0.1:8000"; +const allowedDevOrigins = parseAllowedDevOrigins(process.env.ALLOWED_DEV_ORIGINS); const nextConfig: NextConfig = { /* config options here */ - allowedDevOrigins: ["192.168.0.101"], + ...(allowedDevOrigins.length > 0 ? { allowedDevOrigins } : {}), reactCompiler: true, async rewrites() { return [ diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 0b9c52e..3dd32c2 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,6 +1,5 @@ import type { Metadata } from "next"; import { Geist, Geist_Mono } from "next/font/google"; -import Script from "next/script"; import { Providers } from "@/components/providers"; import "./globals.css"; @@ -37,12 +36,10 @@ export default function RootLayout({ suppressHydrationWarning className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`} > - - - +