From 67d2bddeb6ede0cce6f4e862b2a0ef719adffeb4 Mon Sep 17 00:00:00 2001 From: Woody Date: Mon, 18 May 2026 17:27:28 +0800 Subject: [PATCH] fix: use relative /api/v1 fallback instead of hardcoded localhost:8000 API URLs now resolve relative to the page origin, working for both local dev (via Vite proxy) and remote production deployments. Also fixes useFullTranscript which had a double /api/v1 path bug when VITE_API_BASE_URL was set. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- frontend/src/components/ResponsePanel.tsx | 2 +- frontend/src/hooks/useFullTranscript.ts | 4 ++-- frontend/src/lib/api.ts | 4 ++-- frontend/src/test/components/ResponsePanel.test.tsx | 2 +- frontend/src/utils/citationParser.ts | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/ResponsePanel.tsx b/frontend/src/components/ResponsePanel.tsx index 7cb6319..6058f48 100644 --- a/frontend/src/components/ResponsePanel.tsx +++ b/frontend/src/components/ResponsePanel.tsx @@ -7,7 +7,7 @@ import { getPdfViewerUrl } from '../lib/api' import { processCitations, processCitationsForSubq, extractCitedSources, highlightTerms } from '../utils/citationParser' import { bulletizeMarkdown } from '../utils/citationParser' -const V2_BASE = `${import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:8000/api/v1'}/v2` +const V2_BASE = `${import.meta.env.VITE_API_BASE_URL ?? '/api/v1'}/v2` function getHighlightUrl(document_id: string, chunk_index: number, sub_question: string): string { return `${V2_BASE}/highlights?document_id=${encodeURIComponent(document_id)}&chunk_index=${chunk_index}&sub_question=${encodeURIComponent(sub_question)}` diff --git a/frontend/src/hooks/useFullTranscript.ts b/frontend/src/hooks/useFullTranscript.ts index f12c42a..7848ad2 100644 --- a/frontend/src/hooks/useFullTranscript.ts +++ b/frontend/src/hooks/useFullTranscript.ts @@ -13,8 +13,8 @@ export function useFullTranscript({ videoId }: UseFullTranscriptOptions) { setIsLoading(true) setError(null) try { - const base = import.meta.env.VITE_API_BASE_URL ?? '' - const resp = await fetch(`${base}/api/v1/video/${videoId}/transcribe`, { + const base = import.meta.env.VITE_API_BASE_URL ?? '/api/v1' + const resp = await fetch(`${base}/video/${videoId}/transcribe`, { method: 'POST', }) if (!resp.ok) { diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 65f09dd..3dcd3cb 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -1,7 +1,7 @@ import axios from 'axios' import type { ChunkingStrategy, QueryRequest, QueryResponse, QueryStreamEvent, IngestResponse, DocumentListResponse, ChunkInfo, DeleteResponse, PromptProfileListResponse, PromptSetResponse, PromptUpdateRequest, PromptBatchUpdateRequest, PromptActivateResponse, PromptStatusResponse, ProfileExportData, ProfileImportResponse, QueryHistoryList, QueryHistoryDetail, HistoryStats, HistoryDeleteResponse, FullTranscriptResponse, VideoUploadResponse } from '../types' -const BASE_URL: string = import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:8000/api/v1' +const BASE_URL: string = import.meta.env.VITE_API_BASE_URL ?? '/api/v1' export const apiClient = axios.create({ baseURL: BASE_URL }) @@ -78,7 +78,7 @@ export const deleteChunk = async (chunkId: string): Promise => { } export const getChunkPdfUrl = (filePath: string): string => { - const baseUrl: string = import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:8000/api/v1' + const baseUrl: string = import.meta.env.VITE_API_BASE_URL ?? '/api/v1' return `${baseUrl}/chunks/${encodeURIComponent(filePath)}/pdf` } diff --git a/frontend/src/test/components/ResponsePanel.test.tsx b/frontend/src/test/components/ResponsePanel.test.tsx index e4ebef8..0925da1 100644 --- a/frontend/src/test/components/ResponsePanel.test.tsx +++ b/frontend/src/test/components/ResponsePanel.test.tsx @@ -265,7 +265,7 @@ describe('ResponsePanel', () => { await waitFor(() => { expect(mockFetch).toHaveBeenCalledTimes(1) expect(mockFetch).toHaveBeenCalledWith( - 'http://localhost:8000/api/v1/v2/highlights/batch', + '/api/v1/v2/highlights/batch', expect.objectContaining({ method: 'POST', headers: { 'Content-Type': 'application/json' }, diff --git a/frontend/src/utils/citationParser.ts b/frontend/src/utils/citationParser.ts index b224bd6..86d4f93 100644 --- a/frontend/src/utils/citationParser.ts +++ b/frontend/src/utils/citationParser.ts @@ -61,7 +61,7 @@ export function processCitationsForSubq( function buildCitationUrl(source: SourceMetadata, highlightReady?: boolean): string | null { if (highlightReady && source.document_id && source.sub_question_text) { - const v2Base = `${import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:8000/api/v1'}/v2` + const v2Base = `${import.meta.env.VITE_API_BASE_URL ?? '/api/v1'}/v2` return `${v2Base}/highlights?document_id=${encodeURIComponent(source.document_id)}&chunk_index=${source.chunk_index}&sub_question=${encodeURIComponent(source.sub_question_text)}` } if (source.chunk_file_path) {