Files
web_hgdjb_h5/next.config.ts
T
谢宇宁andClaude Opus 5.5 6fb2b1e486 Initial commit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 22:26:18 +07:00

41 lines
1.4 KiB
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";
/** 构建期兜底代理。请求期以 API_PROXY_TARGET 为准,见 src/lib/api/upstream-proxy.ts。 */
const apiProxyTarget = (process.env.API_PROXY_TARGET || "").replace(/\/$/, "");
const appEnv = process.env.APP_ENV;
const nextConfig: NextConfig = {
output: "standalone",
// 仅在显式 APP_ENV=test|development 时分目录;未设置 / production 仍用 .next
distDir:
appEnv === "test" ? ".next-test" : appEnv === "development" ? ".next-dev" : ".next",
poweredByHeader: false,
cacheComponents: true,
partialPrefetching: true,
// 本机用 127.0.0.1 打开时,允许跨源访问 Next 开发资源
allowedDevOrigins: ["127.0.0.1"],
turbopack: {
rules: {
"*.css": {
loaders: ["@tailwindcss/turbopack"],
as: "*.css",
},
},
},
async rewrites() {
if (!apiProxyTarget) return [];
// fallback:动态 Route Handler(upstream-proxy)优先;避免 afterFiles 抢走
// /api/[...path] 后走 Next httpxy(本机 IPv6 不通时 AggregateError → 500)。
// /h5/m3u8、/enkey、/newenkey 由 route handler(lib/media/proxy)代理,密钥地址不带尾斜杠
const proxy = [
{
source: "/api/:path*",
destination: `${apiProxyTarget}/api/:path*`,
},
];
return { fallback: proxy };
},
};
export default nextConfig;