fix(frontend): remove localhost rewrites and enforce NEXT_PUBLIC_BACKEND_URL
- remove Next.js rewrites to http://127.0.0.1:8000 - require NEXT_PUBLIC_BACKEND_URL in API routes (config, financials, config/test) - prevent accidental fallback to host ports; use container service name backend:8000
This commit is contained in:
parent
3d0fd6f704
commit
230f180dea
@ -13,18 +13,6 @@ const nextConfig = {
|
|||||||
experimental: {
|
experimental: {
|
||||||
proxyTimeout: 300000, // 300 seconds (5 minutes)
|
proxyTimeout: 300000, // 300 seconds (5 minutes)
|
||||||
},
|
},
|
||||||
async rewrites() {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
source: "/api/:path*",
|
|
||||||
destination: "http://127.0.0.1:8000/api/:path*",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
source: "/health",
|
|
||||||
destination: "http://127.0.0.1:8000/health",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
@ -1,14 +1,20 @@
|
|||||||
import { NextRequest } from 'next/server';
|
import { NextRequest } from 'next/server';
|
||||||
|
|
||||||
const BACKEND_BASE = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://127.0.0.1:8000/api';
|
const BACKEND_BASE = process.env.NEXT_PUBLIC_BACKEND_URL;
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
|
if (!BACKEND_BASE) {
|
||||||
|
return new Response('NEXT_PUBLIC_BACKEND_URL 未配置', { status: 500 });
|
||||||
|
}
|
||||||
const resp = await fetch(`${BACKEND_BASE}/config`);
|
const resp = await fetch(`${BACKEND_BASE}/config`);
|
||||||
const text = await resp.text();
|
const text = await resp.text();
|
||||||
return new Response(text, { status: resp.status, headers: { 'Content-Type': resp.headers.get('Content-Type') || 'application/json' } });
|
return new Response(text, { status: resp.status, headers: { 'Content-Type': resp.headers.get('Content-Type') || 'application/json' } });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function PUT(req: NextRequest) {
|
export async function PUT(req: NextRequest) {
|
||||||
|
if (!BACKEND_BASE) {
|
||||||
|
return new Response('NEXT_PUBLIC_BACKEND_URL 未配置', { status: 500 });
|
||||||
|
}
|
||||||
const body = await req.text();
|
const body = await req.text();
|
||||||
const resp = await fetch(`${BACKEND_BASE}/config`, {
|
const resp = await fetch(`${BACKEND_BASE}/config`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
import { NextRequest } from 'next/server';
|
import { NextRequest } from 'next/server';
|
||||||
|
|
||||||
const BACKEND_BASE = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://127.0.0.1:8000/api';
|
const BACKEND_BASE = process.env.NEXT_PUBLIC_BACKEND_URL;
|
||||||
|
|
||||||
export async function POST(req: NextRequest) {
|
export async function POST(req: NextRequest) {
|
||||||
|
if (!BACKEND_BASE) {
|
||||||
|
return new Response('NEXT_PUBLIC_BACKEND_URL 未配置', { status: 500 });
|
||||||
|
}
|
||||||
const body = await req.text();
|
const body = await req.text();
|
||||||
const resp = await fetch(`${BACKEND_BASE}/config/test`, {
|
const resp = await fetch(`${BACKEND_BASE}/config/test`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
import { NextRequest } from 'next/server';
|
import { NextRequest } from 'next/server';
|
||||||
|
|
||||||
const BACKEND_BASE = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://127.0.0.1:8000/api';
|
const BACKEND_BASE = process.env.NEXT_PUBLIC_BACKEND_URL;
|
||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
req: NextRequest,
|
req: NextRequest,
|
||||||
context: { params: Promise<{ slug: string[] }> }
|
context: { params: Promise<{ slug: string[] }> }
|
||||||
) {
|
) {
|
||||||
|
if (!BACKEND_BASE) {
|
||||||
|
return new Response('NEXT_PUBLIC_BACKEND_URL 未配置', { status: 500 });
|
||||||
|
}
|
||||||
const url = new URL(req.url);
|
const url = new URL(req.url);
|
||||||
const { slug } = await context.params;
|
const { slug } = await context.params;
|
||||||
const path = slug.join('/');
|
const path = slug.join('/');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user