fix(部署): 补齐直连前端时的 API 反代

This commit is contained in:
2026-07-03 16:44:44 +08:00
parent 7f4d83f57a
commit 8c4945a03c
7 changed files with 71 additions and 0 deletions

View File

@@ -7,8 +7,25 @@ function toIgnoredList(ignored) {
return entries.filter((entry) => typeof entry === 'string' && entry.length > 0);
}
function toApiProxyDestination(target) {
const cleanTarget = target.trim().replace(/\/+$/, '');
if (!cleanTarget) return null;
const apiBase = cleanTarget.endsWith('/api/v1') ? cleanTarget : `${cleanTarget}/api/v1`;
return `${apiBase}/:path*`;
}
const nextConfig = {
transpilePackages: ['@ftb/shared'],
async rewrites() {
const destination = toApiProxyDestination(process.env.NEXT_API_PROXY_TARGET || '');
if (!destination) return [];
return [
{
source: '/api/v1/:path*',
destination,
},
];
},
webpack(config, { dev }) {
if (dev) {
const ignored = toIgnoredList(config.watchOptions?.ignored);