30 lines
998 B
TypeScript
30 lines
998 B
TypeScript
import type { NextConfig } from "next";
|
||
|
||
/** 本地调试代理目标,见 config/*.env / .env.local 的 API_PROXY_TARGET */
|
||
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 打开本地 dev 时允许 HMR(默认只放行 localhost)
|
||
allowedDevOrigins: ["127.0.0.1"],
|
||
async rewrites() {
|
||
if (!apiProxyTarget) return [];
|
||
return [
|
||
{
|
||
source: "/api/:path*",
|
||
destination: `${apiProxyTarget}/api/:path*`,
|
||
},
|
||
// /h5/m3u8、/enkey、/newenkey 由 route handler 代理,密钥地址不带尾斜杠
|
||
];
|
||
},
|
||
};
|
||
|
||
export default nextConfig;
|