mirror of
https://github.com/velocitatem/cvfs.git
synced 2026-05-31 08:43:37 +00:00
Fix API URL config: use Next.js rewrite proxy instead of NEXT_PUBLIC_*
NEXT_PUBLIC_* is baked at build time so runtime docker-compose environment vars have no effect. Instead: - next.config.ts rewrites /api/* -> API_BASE_URL/api/* at the server level - api.ts uses relative paths (no env var in client bundle at all) - docker-compose passes API_BASE_URL=http://cvfs-backend:8080 at runtime - Dockerfile no longer needs any build args Requests: browser -> Next.js server (/api/*) -> cvfs-backend:8080 (/api/*) https://claude.ai/code/session_01Xmxm2QLgFBgRJyYD6VukR6
This commit is contained in:
@@ -3,6 +3,10 @@ import path from "node:path";
|
|||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
outputFileTracingRoot: path.join(process.cwd(), "../.."),
|
outputFileTracingRoot: path.join(process.cwd(), "../.."),
|
||||||
|
async rewrites() {
|
||||||
|
const backend = process.env.API_BASE_URL ?? "http://localhost:9812";
|
||||||
|
return [{ source: "/api/:path*", destination: `${backend}/api/:path*` }];
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
const API = process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:9812";
|
// Empty base: all API calls go to /api/* which Next.js rewrites to the backend.
|
||||||
|
// The actual backend URL is set via API_BASE_URL env var in next.config.ts (server-side, runtime).
|
||||||
|
const API = "";
|
||||||
|
|
||||||
export type StructuredBlock = {
|
export type StructuredBlock = {
|
||||||
path: string;
|
path: string;
|
||||||
@@ -130,4 +132,3 @@ export async function publishVersion(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export { API as API_BASE_URL };
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ./
|
context: ./
|
||||||
dockerfile: ./docker/webapp.Dockerfile
|
dockerfile: ./docker/webapp.Dockerfile
|
||||||
args:
|
environment:
|
||||||
- NEXT_PUBLIC_API_BASE_URL=https://api.cv.alves.world
|
- API_BASE_URL=http://cvfs-backend:8080
|
||||||
networks:
|
networks:
|
||||||
- dokploy-network
|
- dokploy-network
|
||||||
- cvfs-network
|
- cvfs-network
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ COPY apps/webapp/package.json apps/webapp/bun.lock ./
|
|||||||
RUN bun install --frozen-lockfile
|
RUN bun install --frozen-lockfile
|
||||||
|
|
||||||
FROM deps AS builder
|
FROM deps AS builder
|
||||||
ARG NEXT_PUBLIC_API_BASE_URL=http://localhost:9812
|
|
||||||
ENV NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL
|
|
||||||
COPY apps/webapp ./
|
COPY apps/webapp ./
|
||||||
RUN bun run build
|
RUN bun run build
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user