diff --git a/docker-compose.yml b/docker-compose.yml index e7f6c1c..4ffecdb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,10 +22,8 @@ services: web: build: context: ./web - args: - NEXT_PUBLIC_API_BASE_URL: http://127.0.0.1:8000/api/v1 environment: - NEXT_PUBLIC_API_BASE_URL: http://127.0.0.1:8000/api/v1 + API_INTERNAL_URL: http://backend:8000 ports: - "3000:3000" depends_on: diff --git a/web/.env.example b/web/.env.example index 8ac7c80..26d3a8f 100644 --- a/web/.env.example +++ b/web/.env.example @@ -1 +1 @@ -NEXT_PUBLIC_API_BASE_URL=http://127.0.0.1:8000/api/v1 +API_INTERNAL_URL=http://127.0.0.1:8000 diff --git a/web/Dockerfile b/web/Dockerfile index b42aa5c..a8ea746 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -5,8 +5,6 @@ RUN npm ci FROM node:22-alpine AS builder WORKDIR /app -ARG NEXT_PUBLIC_API_BASE_URL=http://127.0.0.1:8000/api/v1 -ENV NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL COPY --from=deps /app/node_modules ./node_modules COPY . . RUN npm run build @@ -16,6 +14,7 @@ WORKDIR /app ENV NODE_ENV=production ENV HOSTNAME=0.0.0.0 ENV PORT=3000 +ENV API_INTERNAL_URL=http://backend:8000 COPY --from=builder /app ./ EXPOSE 3000 CMD ["npm", "run", "start"] diff --git a/web/lib/api.ts b/web/lib/api.ts index afcc1ca..0a161ee 100644 --- a/web/lib/api.ts +++ b/web/lib/api.ts @@ -1,4 +1,4 @@ -export const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || "http://127.0.0.1:8000/api/v1"; +export const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || "/api/v1"; const TOKEN_KEY = "cyber_mister_token"; const CLIENT_KEY = "cyber_mister_client_id"; diff --git a/web/next.config.ts b/web/next.config.ts index 2f6491c..fdccc03 100644 --- a/web/next.config.ts +++ b/web/next.config.ts @@ -2,6 +2,16 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { reactStrictMode: true, + async rewrites() { + const apiInternalUrl = process.env.API_INTERNAL_URL || "http://127.0.0.1:8000"; + + return [ + { + source: "/api/:path*", + destination: `${apiInternalUrl}/api/:path*`, + }, + ]; + }, }; export default nextConfig;