@@ -0,0 +1,40 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user