Files
lotteryFront/next.config.ts
kang 03faed1db6 feat: 更新 API 路径配置并优化环境变量管理
- 修改 .env.example,更新玩家端本地配置说明,新增直连 Laravel 和局域网 IP 访问配置项,提升开发灵活性。
- 更新 middleware.ts,使用新的 LOTTERY_API_V1_BASE 常量构建 API 请求路径,简化代码结构。
- 在 next.config.ts 中引入 parseAllowedDevOrigins 函数,动态解析允许的开发来源,增强安全性。
- 重构多个 API 模块,移除 API_V1_PREFIX,直接使用相对路径,简化 API 调用逻辑,提高可维护性。
2026-05-29 10:28:43 +08:00

35 lines
878 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { NextConfig } from "next";
import { nonCspSecurityHeaders } from "./src/lib/csp-config";
import { parseAllowedDevOrigins } from "./src/lib/next-dev-origins";
const lotteryApiProxyTarget =
process.env.API_BASE_URL?.trim() || "http://127.0.0.1:8000";
const allowedDevOrigins = parseAllowedDevOrigins(process.env.ALLOWED_DEV_ORIGINS);
const nextConfig: NextConfig = {
...(allowedDevOrigins.length > 0 ? { allowedDevOrigins } : {}),
reactCompiler: true,
// 非 CSP 安全头CSP 由 middleware 按后台接入站点白名单动态生成。
async headers() {
return [
{
source: "/:path*",
headers: nonCspSecurityHeaders,
},
];
},
async rewrites() {
return [
{
source: "/api/:path*",
destination: `${lotteryApiProxyTarget}/api/:path*`,
},
];
},
};
export default nextConfig;