Move API base URL to server-side configuration via Next.js rewrites

This commit is contained in:
Daniel Alves Rösel
2026-04-02 22:24:46 +04:00
committed by GitHub
3 changed files with 8 additions and 3 deletions

View File

@@ -3,6 +3,10 @@ import path from "node:path";
const nextConfig: NextConfig = {
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;

View File

@@ -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 = {
path: string;
@@ -130,4 +132,3 @@ export async function publishVersion(
});
}
export { API as API_BASE_URL };

View File

@@ -12,7 +12,7 @@ services:
context: ./
dockerfile: ./docker/webapp.Dockerfile
environment:
- NEXT_PUBLIC_API_BASE_URL=https://api.cv.alves.world
- API_BASE_URL=http://cvfs-backend:8080
networks:
- dokploy-network
- cvfs-network