Commit 2fb86513 by 黄南光

前端接口改走同源 /api 反向代理

next.config.ts 加 rewrites 把 /api/* 转发到内网 backend:8104;前端 API_BASE 默认改为 /api;docker-compose 移除 NEXT_PUBLIC_API_URL,改用运行时 BACKEND_INTERNAL_URL。避免暴露 8104、跨域及 https mixed-content。
1 parent 58ee6ca7
......@@ -24,14 +24,13 @@ services:
build:
context: ./frontend
dockerfile: Dockerfile
args:
- NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL:-http://localhost:8104}
container_name: wiki-frontend
restart: always
depends_on:
- backend
environment:
- NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL:-http://localhost:8104}
# 前端容器内 Next.js server 反代 /api 到后端的内网地址(运行时生效,改地址无需重新构建)
- BACKEND_INTERNAL_URL=${BACKEND_INTERNAL_URL:-http://backend:8104}
ports:
- "3001:3000"
......
......@@ -2,6 +2,14 @@ import type { NextConfig } from "next";
const nextConfig: NextConfig = {
allowedDevOrigins: ["192.168.1.71"],
async rewrites() {
return [
{
source: "/api/:path*",
destination: `${process.env.BACKEND_INTERNAL_URL || "http://backend:8104"}/:path*`,
},
];
},
};
export default nextConfig;
......@@ -171,7 +171,7 @@ export default function EnterpriseWiki() {
// Selection state
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
const API_BASE = process.env.NEXT_PUBLIC_API_URL || (typeof window !== 'undefined' ? `http://${window.location.hostname}:8104` : "http://127.0.0.1:8104");
const API_BASE = process.env.NEXT_PUBLIC_API_URL || "/api";
const fetchFiles = async (page = currentPage, size = pageSize, search = searchQuery, isInitial = false) => {
if (isInitial) setIsInitialLoading(true);
......
......@@ -6,7 +6,7 @@ import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
import { cn } from "@/lib/utils";
const API_BASE = process.env.NEXT_PUBLIC_API_URL || (typeof window !== 'undefined' ? `http://${window.location.hostname}:8104` : "http://127.0.0.1:8104");
const API_BASE = process.env.NEXT_PUBLIC_API_URL || "/api";
interface TreeNodeData {
name: string;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!