diff --git a/frontend/src/api/files.ts b/frontend/src/api/files.ts index ed9effff..bfe859b1 100644 --- a/frontend/src/api/files.ts +++ b/frontend/src/api/files.ts @@ -2,10 +2,8 @@ import { useQuery } from '@tanstack/react-query' import { API_BASE_URL } from '@/config' import type { FileInfo, ChunkedFileInfo, PatchOperation } from '@/types/files' -const API_BASE = API_BASE_URL - async function fetchFile(path: string): Promise { - const response = await fetch(`${API_BASE}/api/files/${path}`) + const response = await fetch(`${API_BASE_URL}/api/files/${path}`) if (!response.ok) { throw new Error(`Failed to load file: ${response.statusText}`) @@ -23,7 +21,7 @@ export function useFile(path: string | undefined) { } export async function fetchFileRange(path: string, startLine: number, endLine: number): Promise { - const response = await fetch(`${API_BASE}/api/files/${path}?startLine=${startLine}&endLine=${endLine}`) + const response = await fetch(`${API_BASE_URL}/api/files/${path}?startLine=${startLine}&endLine=${endLine}`) if (!response.ok) { throw new Error(`Failed to load file range: ${response.statusText}`) @@ -33,7 +31,7 @@ export async function fetchFileRange(path: string, startLine: number, endLine: n } export async function applyFilePatches(path: string, patches: PatchOperation[]): Promise<{ success: boolean; totalLines: number }> { - const response = await fetch(`${API_BASE}/api/files/${path}`, { + const response = await fetch(`${API_BASE_URL}/api/files/${path}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ patches }), diff --git a/frontend/src/api/git.ts b/frontend/src/api/git.ts index fe1aeca4..968a4dab 100644 --- a/frontend/src/api/git.ts +++ b/frontend/src/api/git.ts @@ -2,10 +2,8 @@ import { useQuery } from '@tanstack/react-query' import { API_BASE_URL } from '@/config' import type { GitStatusResponse, FileDiffResponse } from '@/types/git' -const API_BASE = API_BASE_URL - export async function fetchGitStatus(repoId: number): Promise { - const response = await fetch(`${API_BASE}/api/repos/${repoId}/git/status`) + const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/status`) if (!response.ok) { const error = await response.json().catch(() => ({ error: 'Failed to fetch git status' })) @@ -16,7 +14,7 @@ export async function fetchGitStatus(repoId: number): Promise } export async function fetchFileDiff(repoId: number, path: string): Promise { - const response = await fetch(`${API_BASE}/api/repos/${repoId}/git/diff?path=${encodeURIComponent(path)}`) + const response = await fetch(`${API_BASE_URL}/api/repos/${repoId}/git/diff?path=${encodeURIComponent(path)}`) if (!response.ok) { const error = await response.json().catch(() => ({ error: 'Failed to fetch file diff' })) diff --git a/frontend/src/api/repos.ts b/frontend/src/api/repos.ts index ceba0a7b..9b0b6b7e 100644 --- a/frontend/src/api/repos.ts +++ b/frontend/src/api/repos.ts @@ -1,15 +1,13 @@ import type { Repo } from './types' import { API_BASE_URL } from '@/config' -const API_BASE = API_BASE_URL - export async function createRepo( repoUrl: string, branch?: string, openCodeConfigName?: string, useWorktree?: boolean ): Promise { - const response = await fetch(`${API_BASE}/api/repos`, { + const response = await fetch(`${API_BASE_URL}/api/repos`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ repoUrl, branch, openCodeConfigName, useWorktree }), @@ -24,7 +22,7 @@ export async function createRepo( } export async function listRepos(): Promise { - const response = await fetch(`${API_BASE}/api/repos`) + const response = await fetch(`${API_BASE_URL}/api/repos`) if (!response.ok) { throw new Error('Failed to list repos') @@ -34,7 +32,7 @@ export async function listRepos(): Promise { } export async function getRepo(id: number): Promise { - const response = await fetch(`${API_BASE}/api/repos/${id}`) + const response = await fetch(`${API_BASE_URL}/api/repos/${id}`) if (!response.ok) { throw new Error('Failed to get repo') @@ -44,7 +42,7 @@ export async function getRepo(id: number): Promise { } export async function deleteRepo(id: number): Promise { - const response = await fetch(`${API_BASE}/api/repos/${id}`, { + const response = await fetch(`${API_BASE_URL}/api/repos/${id}`, { method: 'DELETE', }) @@ -54,7 +52,7 @@ export async function deleteRepo(id: number): Promise { } export async function startServer(id: number, openCodeConfigName?: string): Promise { - const response = await fetch(`${API_BASE}/api/repos/${id}/server/start`, { + const response = await fetch(`${API_BASE_URL}/api/repos/${id}/server/start`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ openCodeConfigName }), @@ -68,7 +66,7 @@ export async function startServer(id: number, openCodeConfigName?: string): Prom } export async function stopServer(id: number): Promise { - const response = await fetch(`${API_BASE}/api/repos/${id}/server/stop`, { + const response = await fetch(`${API_BASE_URL}/api/repos/${id}/server/stop`, { method: 'POST', }) @@ -80,7 +78,7 @@ export async function stopServer(id: number): Promise { } export async function pullRepo(id: number): Promise { - const response = await fetch(`${API_BASE}/api/repos/${id}/pull`, { + const response = await fetch(`${API_BASE_URL}/api/repos/${id}/pull`, { method: 'POST', }) @@ -92,7 +90,7 @@ export async function pullRepo(id: number): Promise { } export async function getServerLogs(id: number): Promise { - const response = await fetch(`${API_BASE}/api/repos/${id}/server/logs`) + const response = await fetch(`${API_BASE_URL}/api/repos/${id}/server/logs`) if (!response.ok) { throw new Error('Failed to get server logs') @@ -102,7 +100,7 @@ export async function getServerLogs(id: number): Promise { } export async function switchRepoConfig(id: number, configName: string): Promise { - const response = await fetch(`${API_BASE}/api/repos/${id}/config/switch`, { + const response = await fetch(`${API_BASE_URL}/api/repos/${id}/config/switch`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ configName }), @@ -117,7 +115,7 @@ export async function switchRepoConfig(id: number, configName: string): Promise< } export async function switchBranch(id: number, branch: string): Promise { - const response = await fetch(`${API_BASE}/api/repos/${id}/branch/switch`, { + const response = await fetch(`${API_BASE_URL}/api/repos/${id}/branch/switch`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ branch }), @@ -132,7 +130,7 @@ export async function switchBranch(id: number, branch: string): Promise { } export async function listBranches(id: number): Promise<{ local: string[], remote: string[], current: string | null }> { - const response = await fetch(`${API_BASE}/api/repos/${id}/branches`) + const response = await fetch(`${API_BASE_URL}/api/repos/${id}/branches`) if (!response.ok) { throw new Error('Failed to list branches') diff --git a/frontend/src/components/file-browser/FileDiffView.tsx b/frontend/src/components/file-browser/FileDiffView.tsx index 893ea8d9..1a2e60e0 100644 --- a/frontend/src/components/file-browser/FileDiffView.tsx +++ b/frontend/src/components/file-browser/FileDiffView.tsx @@ -201,7 +201,7 @@ export function FileDiffView({ repoId, filePath, onBack, onOpenFile, isMobile = -
+
{diffData.isBinary ? (

Binary file - cannot display diff

diff --git a/frontend/src/components/file-browser/GitChangesSheet.tsx b/frontend/src/components/file-browser/GitChangesSheet.tsx index d7e5aca9..8c885245 100644 --- a/frontend/src/components/file-browser/GitChangesSheet.tsx +++ b/frontend/src/components/file-browser/GitChangesSheet.tsx @@ -65,7 +65,7 @@ export function GitChangesSheet({ isOpen, onClose, repoId, currentBranch, repoLo className="w-screen h-screen max-w-none max-h-none p-0 bg-background border-0 flex flex-col" hideCloseButton > -
+

diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 8c8689b2..b5c9a26f 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -1,37 +1,42 @@ import path from "path"; -import { defineConfig } from "vite"; +import { defineConfig, loadEnv } from "vite"; import react from "@vitejs/plugin-react"; import tailwindcss from "@tailwindcss/vite"; -export default defineConfig({ - envDir: path.resolve(__dirname, ".."), - plugins: [react(), tailwindcss()], - resolve: { - alias: { - "@": path.resolve(__dirname, "./src"), - }, - }, - server: { - host: "0.0.0.0", - port: 5173, - proxy: { - "/api": { - target: "http://localhost:5003", - changeOrigin: true, +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, path.resolve(__dirname, ".."), ""); + const backendPort = env.PORT || 5001; + + return { + envDir: path.resolve(__dirname, ".."), + plugins: [react(), tailwindcss()], + resolve: { + alias: { + "@": path.resolve(__dirname, "./src"), }, }, - }, - build: { - assetsInlineLimit: 4096, - rollupOptions: { - output: { - assetFileNames: (assetInfo) => { - if (assetInfo.name === "manifest.json") { - return "manifest.json"; - } - return "assets/[name]-[hash][extname]"; + server: { + host: "0.0.0.0", + port: 5173, + proxy: { + "/api": { + target: `http://localhost:${backendPort}`, + changeOrigin: true, }, }, }, - }, + build: { + assetsInlineLimit: 4096, + rollupOptions: { + output: { + assetFileNames: (assetInfo) => { + if (assetInfo.name === "manifest.json") { + return "manifest.json"; + } + return "assets/[name]-[hash][extname]"; + }, + }, + }, + }, + }; });