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`} > - - - +