From b02f671aebc41327307787162cdbe521d779f95e Mon Sep 17 00:00:00 2001 From: Khoa Vo Date: Thu, 14 May 2026 17:59:50 +0700 Subject: [PATCH] fix: use relative /api URLs through Next.js proxy instead of direct backend URL --- Dockerfile | 7 +------ frontend/app/channel/[id]/page.tsx | 2 +- frontend/app/feed/library/page.tsx | 2 +- frontend/app/feed/subscriptions/page.tsx | 2 +- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 44818d6..41a2f94 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,13 +18,11 @@ COPY frontend/package.json frontend/package-lock.json ./ RUN npm ci FROM node:20-alpine AS frontend-builder -ARG NEXT_PUBLIC_API_URL=http://127.0.0.1:8080/api WORKDIR /app COPY --from=frontend-deps /app/node_modules ./node_modules COPY frontend/ ./ ENV NEXT_TELEMETRY_DISABLED 1 -ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} -RUN echo "NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL" && npm run build +RUN npm run build # ---- Final Unified Image ---- FROM alpine:latest @@ -57,9 +55,6 @@ ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 ENV KVTUBE_DATA_DIR=/app/data ENV GIN_MODE=release -ARG NEXT_PUBLIC_API_URL=http://127.0.0.1:8080/api -ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} - RUN addgroup -S kvtube && adduser -S kvtube -G kvtube && chown -R kvtube:kvtube /app USER kvtube diff --git a/frontend/app/channel/[id]/page.tsx b/frontend/app/channel/[id]/page.tsx index 41a195a..df6b5f2 100644 --- a/frontend/app/channel/[id]/page.tsx +++ b/frontend/app/channel/[id]/page.tsx @@ -28,7 +28,7 @@ function formatSubscribers(count: number): string { // We no longer need getAvatarColor as we now use the global --yt-avatar-bg -const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'http://127.0.0.1:8080/api'; +const API_BASE = 'http://localhost:8080/api'; async function getChannelInfo(id: string) { try { diff --git a/frontend/app/feed/library/page.tsx b/frontend/app/feed/library/page.tsx index 4f479c9..ed66533 100644 --- a/frontend/app/feed/library/page.tsx +++ b/frontend/app/feed/library/page.tsx @@ -222,7 +222,7 @@ export default function LibraryPage() { useEffect(() => { async function fetchData() { try { - const apiBase = process.env.NEXT_PUBLIC_API_URL || 'http://127.0.0.1:8080/api'; + const apiBase = '/api'; const [historyRes, subsRes] = await Promise.all([ fetch(`${apiBase}/history?limit=20`, { cache: 'no-store' }), fetch(`${apiBase}/subscriptions`, { cache: 'no-store' }) diff --git a/frontend/app/feed/subscriptions/page.tsx b/frontend/app/feed/subscriptions/page.tsx index 608ceb5..f7dbde2 100644 --- a/frontend/app/feed/subscriptions/page.tsx +++ b/frontend/app/feed/subscriptions/page.tsx @@ -6,7 +6,7 @@ import { getChannelVideosClient, getChannelInfoClient } from '../../clientAction import { VideoData } from '../../constants'; import LoadingSpinner from '../../components/LoadingSpinner'; -const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'http://127.0.0.1:8080/api'; +const API_BASE = '/api'; interface Subscription { channel_id: string;